#include <iostream>
#include <queue>

using namespace std;

typedef struct DOLL
{
	int h, r;
	
	bool operator > (const DOLL& d) const
	{
		return (h > d.h && r > d.r);
	}
	
	bool operator < (const DOLL& d) const
	{
		return (h < d.h && r < d.r);
	}
} D;

typedef struct Node
{
	D d;
	int num;
};

const int MAX = 100;

int n, m;
D A[MAX];
D B[MAX];

void solve()
{
	queue<Node> q;
	int max =0;
	Node n1 = {A[0], 1};
	Node n2 = {B[0], 1};
	q.push(n1);
	q.push(n2);
	while(!q.empty())
	{
		Node current = q.front();
		q.pop();
		
		if(max < current.num)
		{
			max = current.num;
		}
		
		for(int i=0; i<n; i++)
		{
			if(current.d < A[i])
			{
				Node new_node = {A[i], current.num+1};
				q.push(new_node);
				break;
			}
		}
		
		for(int i=0; i<m; i++)
		{
			if(current.d < B[i])
			{
				Node new_node = {B[i], current.num+1};
				q.push(new_node);
				break;
			}
		}
	}
	
	cout << max << endl;
}

int main(int argc, char** argv)
{
	int h, r;
	
	while(cin >> n, n)
	{
		for(int i=0; i<n; i++)
		{
			cin >> A[i].h >> A[i].r;
		}
		
		cin >> m;
		for(int i=0; i<m; i++)
		{
			cin >> B[i].h >> B[i].r;
		}
		
		solve();
	}
}