#include<vector>
#include<iostream>
#include<algorithm>

#define	mp	make_pair
#define	pb	push_back
#define	h	first
#define	r	second

using namespace std;

typedef	pair<int,int>	pii;

vector< vector<int> > child;
vector<int> memo;
// max number of matrioshka which i-th matrioshka can have (i-th one is included)

int rec(int i)
{
	if(memo[i]!=-1)	return memo[i];

	int nmax=1;
	for(int j=0;j<child[i].size();j++)
		nmax=max(nmax,1+rec(child[i][j]));
	return memo[i]=nmax;
}

int main()
{
	while(1){
		vector<pii>	mat;
		int n;	cin>>n;
		for(int i=0,h,r;i<n;i++)	cin>>h>>r,mat.pb(mp(h,r));
		int m;	cin>>m;
		for(int i=0,h,r;i<m;i++)	cin>>h>>r,mat.pb(mp(h,r));
		if(n==0)	break;

		child=vector< vector<int> >(n+m);
		for(int i=0;i<n+m;i++){
			for(int j=0;j<n+m;j++){
				if(mat[i].h>mat[j].h && mat[i].r>mat[j].r)
					child[i].pb(j);
			}
		}

		memo=vector<int>(n+m,-1);
		int ans=0;
		for(int i=0;i<n+m;i++)	ans=max(ans,rec(i));
		cout<<ans<<endl;
	}

	return 0;
}