#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9

#define rep2(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) rep2(i,0,n)
#define ll long long
#define P pair<int,int>
#define pb push_back

int n,m,h[200],r[200],d[200][200];

int main(){
	while(cin>>n&&n){
		rep(i,n)cin>>h[i]>>r[i];
		cin>>m;
		rep(i,m)cin>>h[i+n]>>r[i+n];
		n+=m;
		rep(i,n+m)fill(d[i],d[i]+n+m,INF);
		rep(i,n)rep(j,n){
			if(i==j)d[i][j]=0;
			if(h[i]>h[j]&&r[i]>r[j])d[i][j]=-1;
		}
		rep(k,n)rep(i,n)rep(j,n)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		int ans=0;
		rep(i,n)rep(j,n)ans=max(ans,-d[i][j]+1);
		cout<<ans<<endl;
	}
}