#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

int n, m;
int h1[100], h2[100], r1[100], r2[100];
int next1[100], next2[100];

int calc(int idx, int d)
{
	static int dp[2][100];
	
	if(idx == 0 && d == 0)
		for(int i = 0; i < 2; ++i)
			for(int j = 0; j < max(n, m); ++j)
				dp[i][j] = -1;	
	
	int ret = 0;
	
	if((idx < 0) || (d == 0 && idx >= n) || (d == 1 && idx >= m))
		return 0;
		
	if(dp[d][idx] != -1)
		return dp[d][idx];
	
	ret = calc(idx + 1, d);
	if(d == 0)
		ret = max(ret, calc(next1[idx], 1));
	else
		ret = max(ret, calc(next2[idx], 0));
	
	return dp[d][idx] = ret + 1;
}

int main()
{
	while(true) {
	
		int idx;
		
		scanf("%d", &n);
		if(n == 0)
			break;
		for(int i = 0; i < n; ++i)
			scanf("%d%d", &h1[i], &r1[i]), next1[i] = -1;
		scanf("%d", &m);
		if(m == 0)
			break;
		for(int i = 0; i < m; ++i)
			scanf("%d%d", &h2[i], &r2[i]), next2[i] = -1;
		
		idx = 0;
		for(int i = 0; i < n; ++i) {
			
			while(idx < m) {
				if(h1[i] < h2[idx] && r1[i] < r2[idx])
					break;
				++idx;
			}
			if(idx >= m)
				break;
			next1[i] = idx;
		}
		
		idx = 0;
		for(int i = 0; i < m; ++i) {
			
			while(idx < n) {
				if(h2[i] < h1[idx] && r2[i] < r1[idx])
					break;
				++idx;
			}
			if(idx >= n)
				break;
			next2[i] = idx;
		}
		
		int ans = max(calc(0, 0), calc(0, 1));
		
		printf("%d\n", ans);
	}
	
	return 0;
}