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

struct Doll{
  int h,r;
  Doll(int a,int b){h=a;r=b;};
};

int n;
int h,r;
int m;
vector<Doll>doll;
int memo[201]={0};

bool comp(Doll a, Doll b){return a.h<b.h && a.r<b.r;};

int rec(int id)
{
  int ans=0;
  for(int i=0;i<n+m;i++){
    if(comp(doll[i],doll[id]))ans=max(rec(i)+1,ans);
  }

  return ans;
}

int main()
{
  while(cin>>n,n){
    doll.clear();
    for(int i=0;i<200;i++)memo[i]=0;

    for(int i=0;i<n;i++){
      cin>>h>>r;
      doll.push_back(Doll(h,r));
    }
    cin>>m;
    for(int i=0;i<m;i++){
      cin>>h>>r;
      doll.push_back(Doll(h,r));
    }

    doll.push_back(Doll(1001,1001));

    cout<<rec(n+m)<<endl;
  }
}