#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  int n,m,x,y;
  while(cin >>n,n){
    vector<pair<int, int> > doll;
    vector<int> lot;
    int dp[201] = {0};
    int ans = 0;
    for(int i=0; i<n; i++){cin >>x>>y;doll.push_back(make_pair(x,y));}
    cin >>m;
    for(int i=0; i<m; i++){cin >>x>>y;doll.push_back(make_pair(x,y));}
    sort(doll.begin(),doll.end());
    lot.push_back(0);
    for(int i=0,r=-1; i<doll.size(); i++){
      if(r != doll[i].first){
	r = doll[i].first;
	lot.push_back(doll[i].second);
      }
    }
    for(int i=1; i<lot.size(); i++){
      int r = 0;
      for(int j=0; j<i; j++){
	if(lot[j]<lot[i] && r<dp[j]){r = dp[j];}
      }
      dp[i] = r+1;
    }
    for(int i=0;i<lot.size();i++){
      if(ans<dp[i]){ans = dp[i];}
    }
    cout <<ans<<endl;
  }
  return 0;
}