#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long

bool sorter(const pair<int, int> p1, const pair<int, int> p2){
  if(p1.fi == p2.fi) return p1.se > p2.se;
  else return p1.fi < p2.fi;
}

int main(){
  int n;
  while(cin>>n, n){
    vector<pair<int, int> > vec(n);
    rep(i,n) scanf("%d %d", &vec[i].fi, &vec[i].se);
    int m;
    cin>>m;
    vec.resize(n+m);
    repl(i,n,n+m) scanf("%d %d", &vec[i].fi, &vec[i].se);
    sort(all(vec), sorter);
    vector<int> lis(n+m, INF);
    rep(i,n+m){
      int idx = lower_bound(all(lis), vec[i].se) - lis.begin();
      lis[idx] = vec[i].se;
    }
    cout << lower_bound(all(lis), INF) - lis.begin() << endl;
  }

  return 0;
}