# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };

int n;
vi h, r;
int memo[2000][2000];
int dp(int H, int R)
{
	if (memo[H][R] != -1)return memo[H][R];
	int ans=0;
	for (int i = 0; i < n; i++)
	{
		if (h[i] > H&&r[i] > R)
		{
			ans = max(ans, dp(h[i], r[i]));
		}
	}
	ans++;
	return memo[H][R] = ans;
}
int main()
{
	while (cin >> n&&n)
	{
		memset(memo, -1, sizeof memo);
		h.clear();
		r.clear();
		FOR(i, n)
		{
			INT(H); INT(R);
			h.push_back(H);
			r.push_back(R);
		}
		INT(m);
		n += m;
		FOR(i, m)
		{
			INT(H); INT(R);
			h.push_back(H);
			r.push_back(R);
		}
		cout << dp(0, 0)-1 << endl;
	}
}