#include <iostream>
#include <vector>
#include <cstring>
#include <cmath>
using namespace std;

typedef pair<int, int> P;

int m,n;
int dp[1002][1002];
vector<P> v(200);

int rec(int h, int r)
{
    if(dp[h][r] >= 0) 
        return dp[h][r];
    
    int ret = 0;
    for(int i = 0; i < m + n; i++) {
        if(v[i].first < h && v[i].second < r) {
            ret = max(ret, rec(v[i].first, v[i].second) + 1);
        }
    }
    
    return dp[h][r] = ret;
}

int main()
{
    while(cin >> n && n) {
        v.clear();
        int h,r;
        for(int i = 0; i < n; i++) {
            cin >> h >> r;
            v.push_back(P(h, r));
        }

        cin >> m;
        for(int i = 0; i < m; i++) {
            cin >> h >> r;
            v.push_back(P(h, r));
        }
        
        memset(dp, -1, sizeof(dp));
        cout << rec(1001, 1001) << endl;
    }
}