#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct DOLL{
	int h;
	int r;
};

int memo[1001][1001];

int f(vector<DOLL> &d1, vector<DOLL> &d2, int h, int r,int i1,int i2)
{
	if( memo[r][h] >= 0 ){
		return memo[r][h];
	}


	int ans = 0;

	for(int i=i1;i<d1.size();i++){
		DOLL &d=d1[i];
		if( d.r>r && d.h>h ){
			int a = f(d1,d2,d.h,d.r,i+1,i2)+1;
			ans = max(a,ans);
			break;
		}
	}

	for(int i=i2;i<d2.size();i++){
		DOLL &d=d2[i];
		if( d.r>r && d.h>h ){
			int a = f(d1,d2,d.h,d.r,i1,i2+1)+1;
			ans = max(a,ans);
			break;
		}
	}

	memo[r][h] = ans;	

	return ans;
}

int main() {

	while (true){

		for(int i=0;i<1001;i++){
			fill(memo[i],memo[i]+1001,-1);
		}

		vector<DOLL> d1;
		vector<DOLL> d2;
		int n,m;

		cin >> n;
		if (n == 0) break;

		for (int i = 0; i<n; i++){
			DOLL d;
			cin >> d.h >> d.r;
			d1.push_back(d);
		}

		cin >> m;

		for (int i = 0; i<m; i++){
			DOLL d;
			cin >> d.h >> d.r;
			d2.push_back(d);
		}

		int ans = f(d1, d2, 0, 0,0,0);
		cout << ans << endl;
	}

	return 0;
}