#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cctype>

#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i,l,n) for(int (i)=(int)(l);(i)<(int)(n);(i)++)
#define d_arr(arr, h, w) rep(i,(h) ){ cout << "["; rep(j,(w) ) { cout << (arr)[i][j] << ", "; } cout << "]" << endl;}
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x);
#define fs first
#define sc second
#define pb push_back

typedef pair<int ,int> P;
vector<P> mv;
map<int, int> memo;

//
int next_of(int i){
    if( i == mv.size()-1 ) { return mv.size(); }
    else if( i >= mv.size()-1 ) { return mv.size(); }
    int h = mv[i].fs;
    int r = mv[i].sc;
    int nh = h;
    int nr = r;
    while(1){
        if( nh > h && nr > r) { break; }
        i++;
        nh = mv[i].fs;
        nr = mv[i].sc;
    }
    return i;
}

// mv[i] 以上で作れるマトリョーシカの数の最大値
int rec(int i){
    //cout << "rec : " << i << endl;
    if( memo.find(i) != memo.end() ){ return memo[i]; }
    if( i == mv.size() ){ return 0; }
    if( mv.size()-1 <= i ){
        return 0;
    }
    int e0 = rec(i+1);
    int e1 = 0;
    int next = next_of(i);
    e1 = rec(next) + 1;
    memo[i] = max(e0,e1);
    return memo[i];
}

int main()
{
    int n,m;
    int h,r;
    while(1){
        mv.clear();
        memo.clear();
        cin >> n;
        if( n==0 ){ break; }
        rep(i,n){
            cin >> h >> r;
            mv.pb(make_pair(h,r));
        }
        cin >> m;
        rep(i,m){
            cin >> h >> r;
            mv.pb(make_pair(h,r));
        }
        sort(mv.begin(),mv.end());
        cout << rec(0) << endl;
    }
}