// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

template<typename Monoid> class SegTree {
  using T = typename Monoid::value_type;

  Monoid m;
  std::vector<T> tree; // 1-indexed
  int size = 1;

  void propTo(int i) { tree[i] = m(tree[i * 2], tree[i * 2 + 1]); }

public:
  SegTree(const int n = 0) {
    while (size < n) size *= 2;
    tree.assign(size * 2, m.id());
  }

  template<typename InputIterator> SegTree(InputIterator first, InputIterator last) {
    int n = std::distance(first, last);
    while (size < n) size *= 2;
    tree.resize(size * 2, m.id());
    std::copy(first, last, tree.begin() + size);
    for (int i = size - 1; i >= 1; i--) propTo(i);
  }

  T fold(int l, int r) { // [l, r)
    T accl = m.id(), accr = m.id();
    for (l += size, r += size; l < r; l /= 2, r /= 2) {
      if (l & 1) accl = m(accl, tree[l++]);
      if (r & 1) accr = m(tree[--r], accr);
    }
    return m(accl, accr);
  }

  void update(int i, const T &x) {
    tree[i += size] = x;
    while (i /= 2) propTo(i);
  }

  const T &operator[](int i) const { return tree[i + size]; }
};

template<typename T, T lowerInf = std::numeric_limits<T>::min()> struct maxMonoid {
  using value_type = T;
  constexpr value_type id() { return lowerInf; }
  constexpr value_type operator()(const value_type &a, const value_type &b) { return a < b ? b : a; }
};

main {
  int n;
  while (cin >> n, n) {
    vpii v(n);
    cin >> v;
    int m;
    cin >> m;
    {
      vpii w(m);
      cin >> w;
      v.reserve(n + m);
      for (auto &x : w) v.push_back(move(x));
    }
    sort(all(v), [](auto &a, auto &b) {
      if (a.first != b.first) return a.first < b.first;
      return a.second > b.second;
    });
    SegTree<maxMonoid<int, 0>> t(1000);
    for (auto &p : v) {
      int &r = p.second;
      t.update(r, t.fold(0, r) + 1);
    }
    cout << t.fold(0, 1000) << endl;
  }
}

Measured memory_bytes: 3076