#include <algorithm>
#include <iostream>
using namespace std;

int N, M, h[200], r[200];

int main() {
    while (true) {
        cin >> N;
        if (N == 0) break;
        for (int j = 0; j < N; ++j) {
            cin >> h[j] >> r[j];
        }
        cin >> M;
        for (int j = 0; j < M; ++j) {
            cin >> h[j+N] >> r[j+N];
        }

        int arr[1001][1001];
        for (int j = 0; j <= 1000; ++j) fill(arr[j], arr[j] + 1001, 0);

        for (int j = 0; j < N+M; ++j) {
            arr[h[j]][r[j]] = 1;
        }

        int dp[1001][1001];
        for (int j = 0; j <= 1000; ++j) fill(dp[j], dp[j] + 1001, 0);

        for (int j = 0; j <= 1000; ++j) {
            for (int k = 0; k <= 1000; ++k) {
                if (j > 0 && k > 0) {
                    dp[j][k] = max(dp[j-1][k-1] + arr[j][k], max(dp[j-1][k], dp[j][k-1]));
                } else if (j > 0) {
                    dp[j][k] = dp[j-1][k];
                } else if (k > 0) {
                    dp[j][k] = dp[j][k-1];
                }
            }
        }

        cout << dp[1000][1000] << endl;
    }
    return 0;
}