#include<cstdio>
#include<vector>
#include<algorithm>
int field1[1001];
int field2[1001];
using namespace std;
int main(void){
    while(1){
        for(int i = 0;i <= 1001;i++){
            field1[i] = 0;
            field2[i] = 0;
        }
        int n; scanf("%d",&n);
        if(n == 0) break;
        vector<pair<int,int> > v1;
        vector<pair<int,int> > v2;
        pair<int,int> p;
        p.first = 0; p.second = 0;
        v1.push_back(p); v2.push_back(p);
        for(int i = 0;i < n;i++){
            int h,r; scanf("%d%d",&h,&r);
            p.first = h; p.second = r;
            v1.push_back(p);
            p.first = r; p.second = h;
            v2.push_back(p);
        }

        scanf("%d",&n);
        for(int i = 0;i < n;i++){
            int h,r; scanf("%d%d",&h,&r);
            p.first = h; p.second = r;
            v1.push_back(p);
            p.first = r; p.second = h;
            v2.push_back(p);
        }

        sort(v1.begin(),v1.end()); sort(v2.begin(),v2.end());
        for(int i = 1;i < v1.size();i++){
            for(int j = i - 1;j >= 0;j--){
                if(v1[i].second > v1[j].second && field1[i] <= field1[j]+1){
                    field1[i] = field1[j]+1;
                }
            }
        }

        for(int i = 1;i < v2.size();i++){
            for(int j = i-1;j >= 0;j--){
                if(v2[i].second > v2[j].second && field2[i] <= field2[j]+1){
                    field2[i] = field2[j]+1;
                }
            }
        }
        int ans = -1;
        for(int i = 0;i < v1.size();i++){
            if(field1[i] >= ans) ans = field1[i];
            if(field2[i] >= ans) ans = field2[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}