#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n,m;
  while(true){
      cin>>n;
      if(n==0) break;
      std::vector<P> v;
      for(int i=0;i<n;i++){
          int h,r;cin>>h>>r;
          v.push_back(P(h,r));
      }
      cin>>m;
      for(int i=0;i<m;i++){
          int h,r;cin>>h>>r;
          v.push_back(P(h,r));
      }
      v.push_back(P(0,0));
      sort(v.begin(),v.end());
      ll dp[n+m+1]={};
      for(int i=1;i<=n+m;i++){
          for(int j=0;j<i;j++){
              int h1=v[i].first,r1=v[i].second,h2=v[j].first,r2=v[j].second;
              if(h2<h1&&r2<r1){
                  dp[i]=max(dp[i],dp[j]+1);
              }
          }
      }
      ll res=-1;
      for(int i=1;i<=n+m;i++)res=max(res,dp[i]);
          cout<<res<<endl;
  }
}