# 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&&r < d.r);
	}
};

struct doll_c{
	doll d;
	int count;
};

int n, m;

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

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