#include <bits/stdc++.h>
using namespace std;

struct doll{
    int h,r;
};

bool operator<(const doll& d1,const doll& d2){
    if(d1.h == d2.h){
        return d1.r > d2.r;
    }
    return d1.h < d2.h;
}

int main() {

    while(1){

        int n;

        cin >> n;

        if(n==0) break;

        int h,r;

        vector<doll> v;
        doll tmp;

        for(int i=0;i<n;i++){
            cin >> h >> r;
            tmp.h = h;
            tmp.r = r;
            v.push_back(tmp);
        }

        int m;

        cin >> m;

        for(int i=0;i<m;i++){
            cin >> h >> r;
            tmp.h = h;
            tmp.r = r;
            v.push_back(tmp);
        }

        sort(v.begin(),v.end());

        /*for(int i=0;i<n+m;i++){
            cout << v[i].h << " " << v[i].r << endl;
        }*/

        int dp[1001] = {0};

        for(int i=0;i<n+m;i++){
            int dm = 0;
            for(int j=0;j<v[i].r;j++){
                dm = max(dm,dp[j]);
            }
            dp[v[i].r] = dm+1;
        }

        int ans = 0;

        for(int i=0;i<1001;i++){
            //cout << dp[i] << endl;
            ans = max(dp[i],ans);
        }

        cout << ans << endl;


    }

    return 0;
}