#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int N,M;
	while(scanf("%d",&N),N){
		vector < Pii > data;
		rep(i,N){
			int a,b;
			scanf("%d%d",&a,&b);
			data.PB(Pii(a,b));
		}
		scanf("%d",&M);
		rep(i,M){
			int a,b;
			scanf("%d%d",&a,&b);
			data.PB(Pii(a,b));
		}
		sort(data.begin(),data.end());
		int l = -1;
		int ans = 0;
		int prev1,prev2;
		prev1 = prev2 = -1;
		rep(i,N+M){
			if(prev1 < data[i].fi && prev2 < data[i].se){
				prev1 = data[i].fi;
				prev2 = data[i].se;
				ans++;
			}
		}
		printf("%d\n",ans);
	}

    return 0;
}