#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
int n, m, ans;
pair<int, int> doll[200];
int dp[1000][1000];
int main()
{
	while(cin >> n && n)
	{
		memset(dp, -1, sizeof(dp));
		ans = 0;
		dp[0][0] = 0;
		for(int i = 0; i < n; i++)
			cin >> doll[i].F >> doll[i].S;
		cin >> m;
		for(int i = n; i < n + m; i++)
			cin >> doll[i].F >> doll[i].S;
		sort(doll, doll + n + m);
		for(int i = 0; i < n + m; i++)
			for(int j = 0; j < doll[i].F; j++)
				for(int k = 0; k < doll[i].S; k++)
					dp[doll[i].F][doll[i].S] = max(dp[doll[i].F][doll[i].S], dp[j][k] + 1);

		for(int i = 0; i < 1000; i++)
			for(int j = 0; j < 1000; j++)
				ans = max(ans, dp[i][j]);
			cout << ans << endl;
	}

}