#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_SIZE = 1000;
const int N = 100;

main(){
   int n, m, sizeH, sizeR;
   int dp[MAX_SIZE+1][MAX_SIZE+1];
   int dataH[2][N];
   int dataR[2][N];
   while(cin >> n && n){
      sizeH = sizeR = 0;
      for(int i=0;i<n;++i){
         cin >> dataH[0][i] >> dataR[0][i];
         sizeH = max(sizeH, dataH[0][i]);
         sizeR = max(sizeR, dataR[0][i]);
      }
      cin >> m;
      for(int i=0;i<m;++i){
         cin >> dataH[1][i] >> dataR[1][i];
         sizeH = max(sizeH, dataH[1][i]);
         sizeR = max(sizeR, dataR[1][i]);
      }
      fill(dp[0], dp[MAX_SIZE], -1);
      dp[0][0] = 1;
      for(int i=0;i<sizeH;++i){
         for(int j=0;j<sizeR;++j){
            if(dp[i][j] == -1) continue;
            for(int k=0;k<n;++k){
               if(dataH[0][k] > i && dataR[0][k] > j) dp[dataH[0][k]][dataR[0][k]] = dp[i][j] + 1;
            }
            for(int k=0;k<m;++k){
               if(dataH[1][k] > i && dataR[1][k] > j) dp[dataH[1][k]][dataR[1][k]] = dp[i][j] + 1;
            }
         }
      }
      int ans = 0;
      for(int i=0;i<sizeH;++i){
         for(int j=0;j<sizeR;++j){
            ans = max(ans, dp[i][j]);
         }
      }
      cout << ans << endl;
   }
   return 0;
}