#include<iostream>
#include<vector>
#include<cstring>
#include<cstdlib>
using namespace std;
struct doll{
    int r;
    int h;
};
vector<doll> dolls;
int hen[1010][1010];
int dollnum;
int dp[210];

int solve(int n)
{
    if(dp[n]!= -1){ return dp[n];}
    int ans = 0;
    int temp=0;
    for(int i=0;i<dollnum;i++)
    {
        if(hen[n][i]==1) {temp = solve(i)+1; ans = max(temp,ans);}
    }
    dp[n] = ans;
    return ans;
}
int main()
{
    int n,m;
    while(cin>>n)
    {
        memset(dp,-1,sizeof(dp));
        dolls.clear();
        memset(hen,0,sizeof(hen));
        if(n==0)break;
        doll temp;
        temp.h=0;temp.r=0;
        dolls.push_back(temp);
        for(int i=0;i<n;i++)
        {
            cin>>temp.h>>temp.r;
            dolls.push_back(temp);
        }
        cin>>m;
        for(int i=0;i<m;i++)
        {
            cin>>temp.h>>temp.r;
            dolls.push_back(temp);
        }
        dollnum = dolls.size();
        for(int i=0;i<dollnum-1;i++)
        {
            for(int j=0;j<dollnum;j++)
            {
                if(dolls[i].h<dolls[j].h && dolls[i].r<dolls[j].r){hen[i][j] =1;}
                if(dolls[i].h>dolls[j].h && dolls[i].r>dolls[j].r){hen[j][i] =1;}
            }
        }
        cout << solve(0)<< endl;
    }
    
    return 0;
}