//Solution for aoj:0157 Russian Dolls
#include<iostream>
#include<algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;
typedef pair<int, int>P;
const int INF = 1 << 30;

int main(){
	int n, m, a, b;
	P doll[201];
	int dp[201];
	while (cin >> n && n){
		fill(dp, dp + 201, INF);
		for (int i = 0; i < n; i++){
			cin >> a >> b;
			doll[i] = P(a, b);
		}
		cin >> m;
		for (int i = n; i < n + m; i++){
			cin >> a >> b;
			doll[i] = P(a, b);
		}
		sort(doll, doll + n + m);
		for (int i = 0; i < n + m; i++){
			if (doll[i].first == doll[i - 1].first){
				doll[i] = P(0, 0);
			}
		}
		for (int i = 0; i < n + m; i++){
			*lower_bound(dp, dp + n + m, doll[i].second) = doll[i].second;
		}
		cout << lower_bound(dp, dp + n + m, INF) - dp << endl;
	}
}