#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	for (int N; cin >> N, N;) {
		vector< pair<int, int> > v;
		for (int i = 0; i < N; i++) {
			int a, b; scanf("%d%d", &a, &b);
			v.push_back(make_pair(a, -b));
		}
		int M; cin >> M;
		for (int i = 0; i < M; i++) {
			int a, b; scanf("%d%d", &a, &b);
			v.push_back(make_pair(a, -b));
		}
		sort(v.begin(), v.end());
		for (int i = 0; i < N + M; i++) {
			v[i].second *= -1;
		}

		vector<int> dp(N + M, INF);
		for (int i = 0; i < N + M; i++) {
			*lower_bound(dp.begin(), dp.end(), v[i].second) = v[i].second;
		}
		int ans = find(dp.begin(), dp.end(), INF) - dp.begin();
		cout << ans << endl;
	}
	return 0;
}