//Solution for aoj:0157 Russian Dolls
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int, int>P;
const int INF = 1 << 29;
int n, m, p;
pair<int, int> doll[201];
int dp[2][201], dp2[201];
int main(){
	while (cin >> n){
		if (!n)
			return 0;
		fill(dp[0], dp[0] + 201, INF);
		fill(dp[1], dp[1] + 201, INF);
		fill(dp2, dp2 + 201, INF);
		for (int i = 0; i < n; i++){
			int a, b;
			cin >> a >> b;
			doll[i].first = a;
			doll[i].second = b;
		}
		cin >> m;
		for (int i = n; i < n + m; i++){
			int a, b;
			cin >> a >> b;
			doll[i].first = a;
			doll[i].second = b;
		}
		sort(doll, doll + n + m);
		for (int i = 0; i < n + m; i++){
			if (doll[i].first == doll[i - 1].first){
				doll[i].first = 0;
				doll[i].second = 0;
			}
		}
		for (int i = 0; i < n + m; i++){
			*lower_bound(dp[0], dp[0] + n + m, doll[i].second) = doll[i].second;
		}
		cout << lower_bound(dp[0], dp[0] + n + m, INF) - dp[0] << endl;
	}
}