# define _CRT_SECURE_NO_WARNINGS
# include <cstdio>
# include <algorithm>

#define MAX 100

struct doll{
	int high, r;
	doll() {}
	doll(int H, int R) : high(H), r(R) {}
	bool operator<(doll d){
		return (high < d.high) ? true : (high == d.high) ? (r < d.r) ? true : false : false;
	}
};

int n, m;

doll K[MAX * 2];
int dp[MAX * 2];

int main(){
	while (1){
		int h, r;
		scanf("%d", &n);
		if (n == 0)
			break;
		for (int i = 0; i < n; ++i){
			scanf("%d %d", &h, &r);
			K[i].high = h; K[i].r = r;
		}
		scanf("%d", &m);
		for (int i = n; i < m+n; ++i){
			scanf("%d %d", &h, &r);
			K[i].high = h;
			K[i].r = r;
		}
		std::sort(K + 1, K + 1 + n + m);
		memset(dp, 0,n+m);
		for (int i = 0; i < n + m; ++i){
			for (int j = 0; j < n + m; ++j){
				if (K[j] < K[i])
					dp[i] = std::max(dp[i], dp[j] + 1);
			}
		}
		printf("%d\n", dp[n + m-1]);
	}
	return 0;
}