#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
 
int dp[1010][1010];
int n, m, h, r;
 
signed main(){
    while (cin >> n && n) {
        rep(i, 0, 1010) {
            rep(j, 0, 1010) {
                dp[i][j] = 0;
            }
        }
        vector<pii> doll;
        rep(i, 0, n) {
            cin >> h >> r;
            doll.push_back(make_pair(h, r));
        }
        cin >> m;
        rep(i, 0, m) {
            cin >> h >> r;
            doll.push_back(make_pair(h, r));
        }
        sort(all(doll));
        rep(i, 0, n + m + 1) {
            rep(j, 1, 1010) {
                if (doll[i].se == j) {
                    dp[i + 1][j] = dp[i][j - 1] + 1;
                }
                else {
                    dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - 1]);
                }
            }
        }
        cout << dp[n + m][1001] << endl;
    }
}