#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())
map<PII,int> memo;
int dfs(int h,int r,int n,vector<PII>& ich,vector<PII>& ji){
  if(memo.find(PII(h,r))!=memo.end()){
    int m = memo[PII(h,r)];
    if(m>=n) return m;
  }
  int ret=n;
  REP(i,ich.size()){
    if(ich[i].first<h&&ich[i].second<r){
      ret = max(ret,dfs(ich[i].first,ich[i].second,n+1,ich,ji));
      break;
    }
  }
  REP(i,ji.size()){
    if(ji[i].first<h&&ji[i].second<r){
      ret = max(ret,dfs(ji[i].first,ji[i].second,n+1,ich,ji));
      break;
    }
  }
  return ret;
}
int main(void){
  int n,m;
  while(cin>>n,n){
    vector<PII> ich;
    vector<PII> ji;
    REP(i,n){
      int h,r;
      cin>>h>>r;
      ich.push_back(PII(h,r));
    } 
    cin>>m;
    REP(i,m){
      int h,r;
      cin>>h>>r;
      ji.push_back(PII(h,r));
    }
    reverse(ich.begin(),ich.end());
    reverse(ji.begin(),ji.end());
    cout<<dfs(INF,INF,0,ich,ji)<<endl;
  }
  return 0;
}