#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

int nm;
vector<pair<int,int> > mat;
vector<vector<int> > DP;

int slave(int h,int r){
    if(DP[h][r] >= 0) return DP[h][r];
    int ret = 0;
    for(int i=0;i<nm;i++){
        if(h < mat[i].first && r < mat[i].second){
            ret = max(ret,slave(mat[i].first,mat[i].second)+1);
        }
    }
    return DP[h][r] = ret;
}

int main(){
    while(true){
        mat.clear();
        DP.clear();
        int n,m;
        cin >> n;
        if(n==0) return 0;
        for(int i=0;i<n;i++){
            int h,r;
            cin >> h >> r;
            mat.push_back(make_pair(h,r));
        }
        cin >> m;
        for(int i=0;i<m;i++){
            int h,r;
            cin >> h >> r;
            mat.push_back(make_pair(h,r));
        }
        nm = n+m;
        for(int i=0;i<1002;i++){
            DP.push_back(vector<int>(1002,-1));
        }
        cout << slave(0,0) << endl;

    }
    return 0;
}