#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
  int i,j,a,b,n,m,hn[100],rn[100],hm[100],rm[100],h[201],r[201],k[2],L[201],max;
  while(1){
    cin >> n;
    if(n == 0) break;
    for(i=0;i<n;i++) cin >> hn[i] >> rn[i];
    cin >> m;
    for(i=0;i<m;i++) cin >> hm[i] >> rm[i];

    a = 0;
    b = 0;
    h[0] = -1;
    r[0] = -1;
    for(i=1;i<=m+n;i++){
      if(a < n && b < m && hn[a] < hm[b] || a < n && b >= m){
	  h[i] = hn[a];
	  r[i] = rn[a++];
	}
      else{
	h[i] = hm[b];
	r[i] = rm[b++];
      }
    }

      k[0] = 0;
      L[0] = 0;
      for(i=1;i<=m+n;i++){
	max = 0;
	for(j=0;j<i;j++){
	  if(L[j] > max && h[j] < h[i] && r[j] < r[i]) max = L[j];
	}
	L[i] = max + 1;
	if(k[0] < L[i]) k[0] = L[i];
      }

      a = 0;
      b = 0;
    for(i=1;i<=m+n;i++){
      if(a < n && b < m && rn[a] < rm[b] || a < n && b >= m){
	  h[i] = hn[a];
	  r[i] = rn[a++];
	}
      else{
	h[i] = hm[b];
	r[i] = rm[b++];
      }
    }

      k[1] = 0;
      L[0] = 0;
      for(i=1;i<=m+n;i++){
	max = 0;
	for(j=0;j<i;j++){
	  if(L[j] > max && h[j] < h[i] && r[j] < r[i]) max = L[j];
	}
	L[i] = max + 1;
	if(k[1] < L[i]) k[1] = L[i];
      }

      if(k[0] > k[1]) cout << k[0] << endl;
      else cout << k[1] << endl;

  }
  return 0;
}