#include<iostream>
#include<cstdlib>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define MAX 3000
using namespace std;
int test=0;
int n,m;
int dp[MAX+1];
class Doll{
public:
   int h;
   int r;
   bool operator < (const Doll &d)const{
      if(h == d.h)return r < d.h;//hが同じ時ｒで比較
      return h < d.h;//普段はｈで比較
   }
};

Doll Dolls[MAX];

void solve(void){
   dp[0] = 0;
   dp[1] = 1;
   for(int i=0;i<(n+m);i++){
      //dp[i+1] = 1;
      for(int j=0;j<i;j++){
	 if(Dolls[j].r < Dolls[i].r){
	    dp[i+1] = max(dp[i],dp[j+1]+1);
	 }
      }
   }

   cout << dp[n+m] << endl;
}

int main(void){
   int h,r;
   while(1){
      cin >> n;
      if(n==0)break;
      for(int i=0;i<n;i++){
	 cin >> h >> r;
	 Dolls[i].h = h;
	 Dolls[i].r = r;
      }
      cin >> m;
      for(int i=n;i<(n+m);i++){
	 cin >> h >> r;
	 Dolls[i].h = h;
	 Dolls[i].r = r;
      }
      sort(Dolls,Dolls+(n+m)-1);
      solve();
      /*
      rep(i,n+m)
	 cout << Dolls[i].h << " " << Dolls[i].r << " " << dp[i+1] << endl;
      cout << endl;
      */
   }
   return 0;
}