#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


const int SIZE = 101;

int H[SIZE];
int R[SIZE];
int N;

int solve( int hh, int rr ) {
    int res = 0;
    for ( int i = 0; i < N; ++ i ) {
        if ( H[i] < hh && R[i] < rr )
            res = max( res, 1 + solve( H[i], R[i] ) );
    }
    return res;
}

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