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

int N;

int m[200][2];
vector<pair<pair<int, int>, int>> m1, m2;
vector<int> pa[200];

int dfs(int x)
{
  int r = 0;
  for(auto v: pa[x])
    r = max(r, dfs(v));
  return r + 1;
}

int main()
{
  while(true)
  {
    for(int i = 0; i < 200; i++)
      pa[i].clear(), (m[i][0] = m[i][1] = 0);
    m1.clear(); m2.clear();

    N = 0;
    for(int i = 0; i < 2; i++)
    {
      int a;
      cin >> a;
      if(!a)
        return 0;
      for(int j = N; j < a + N; j++)
      {
        cin >> m[j][0] >> m[j][1];
        m1.push_back(make_pair(make_pair(m[j][0], m[j][1]), j));
        m2.push_back(make_pair(make_pair(m[j][1], m[j][0]), j));
      } 
      N += a;
    }
    sort(m1.begin(), m1.end());
    sort(m2.begin(), m2.end());
    for(int i = 0; i < N; i++)
    {
      bool b1 = false, b2 = false;
      for(int j = i + 1; j < N; j++)
      {
        if(!b1 && m1[j].first.second > m1[i].first.second)
          pa[m1[i].second].push_back(m1[j].second), b1 = true;
        if(!b2 && m2[j].first.second > m2[i].first.second)
          pa[m2[i].second].push_back(m2[j].second), b1 = true;
      }
    }
    cout << max(dfs(m1[0].second), dfs(m2[0].second)) - 1 << endl;;
  }
}