#include <iostream>
#include <algorithm>
using namespace std;

const int MAX_N = 201;
const int MAX_H = 1001;
const int MAX_R = MAX_H;
int N;
int H[MAX_N], R[MAX_N];
int T[MAX_H][MAX_R];

int solve() {
  int ans = 0;
  fill(T[0],T[MAX_H],0);
  for(int j = 0; j < MAX_H; ++j) {
    for(int k = 0; k < MAX_R; ++k) {
      for(int i = 0; i < N; ++i) {
	if(H[i] > j && R[i] > k) {
	  T[H[i]][R[i]] = max(T[H[i]][R[i]], T[j][k] + 1);
	  ans = max(ans, T[H[i]][R[i]]);
	}
      }
    }
  }
  return ans;
}

int main() {
  while(cin >> N && N) {
    for(int i = 0; i < N; ++i) cin >> H[i] >> R[i];
    int m;
    cin >> m;
    for(int i = 0; i < m; ++i) cin >> H[N+i] >> R[N+i];
    N += m;
    cout << solve() << endl;
  }
  return 0;
}