#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

const int INF = 10000000;
int main()
{
	int n;
	while(scanf("%d", &n), n){
		vector<pii> doll(n);
		rep(i, n)
			scanf("%d%d", &doll[i].first, &doll[i].second);
		
		int m;
		scanf("%d", &m);
		doll.resize(n+m);
		rep(i, m)
			scanf("%d%d", &doll[n+i].first, &doll[n+i].second);
		
		sort(doll.begin(), doll.end());
		vi dp(n+m, INF);
		rep(i, n+m){
			int id = distance(dp.begin(), lower_bound(dp.begin(), dp.end(), doll[i].second));
			dp[id] = doll[i].second;
		}
		
		int ans;
		for(int i=n+m-1; i>=0; --i){
			if(dp[i] != INF){
				ans = i + 1;
				break;
			}
		}
		
		printf("%d\n", ans);
	}
	
	return 0;
}