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


int n, m;
vector<pair<int, int>> d;
vector<int> dp = { 0 };


int solve(){
	dp[0] = d[0].second;
	for (int i = 1; i < d.size(); i++){
		if (dp.back() < d[i].second){
			dp.push_back(d[i].second);
		}
		else{
			*lower_bound(dp.begin(), dp.end(), d[i].second) = d[i].second;
		}
	}
	return dp.size();
}


template<typename T>
void clear(vector<T>& v){
	vector<T> emp;
	swap(v, emp);
}


int main(){
	while (cin >> n, n){
		for (int i = 0; i < n; i++){
			int h, r;
			cin >> h >> r;
			d.push_back({ h, r });
		}
		cin >> m;
		for (int i = 0; i < m; i++){
			int h, r;
			cin >> h >> r;
			d.push_back({ h, r });
		}

		sort(d.begin(), d.end());

		int ans = solve();

		cout << ans << endl;

		clear(d);
		clear(dp);
		dp.push_back(0);
	}

	return 0;
}