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

using namespace std;

struct doll {
    int x, h;
    bool operator<(const doll& o) const {
        return x < o.x && h < o.h;
    }
};

bool compare_by_x(const doll& a, const doll& b) {
    return a.x < b.x;
}

int n, m;
vector<doll> ds;
vector<int> dp;

int solve(int c) {
    if (0 <= dp[c]) return dp[c];
    for (int i = 0; i < c; i++) {
        if (ds[i] < ds[c]) {
            dp[c] = max(dp[c], solve(i)+1);
        }
    }
    return dp[c];
}

int main() {
    while (cin >> n, n != 0) {
        ds.clear();
        for (int i = 0; i < n; i++) {
            doll d;
            cin >> d.x >> d.h;
            ds.push_back(d);
        }
        cin >> m;
        for (int i = 0; i < m; i++) {
            doll d;
            cin >> d.x >> d.h;
            ds.push_back(d);
        }
        sort(ds.begin(), ds.end(), compare_by_x);
        dp.clear();
        dp.resize(n+m, -1);

        dp[0] = 1;
        int max_mat = 0;
        for (int i = 0; i < n+m; i++) 
            max_mat = max(max_mat, solve(i));
        cout << max_mat << endl;
    }
    return 0;
}
    