#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>

struct MT {
public:
	int w;
	int h;
};

int max(int a, int b) {
	return a > b ? a : b;
}

int main() {
	std::ifstream ifs("input.txt");
	do {
		int n, m;
		std::cin >> n;
		std::vector<MT> mtA;
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			int w, h;
			std::cin >> w;
			std::cin >> h;
			MT m;
			m.w = w;
			m.h = h;
			mtA.push_back(m);
		}

		std::cin >> m;
		for (int i = 0; i < m; i++) {
			int w, h;
			std::cin >> w;
			std::cin >> h;
			MT m;
			m.w = w;
			m.h = h;
			mtA.push_back(m);
		}

		std::sort(mtA.begin(), mtA.end(), [](const MT& lhs, const MT& rhs){return lhs.w < rhs.w; });

		/*
		std::cout << "testtest" << std::endl;
		for (int i = 0; i < n + m; i++) {
			std::cout << mtA[i].w << std::endl;
		}
		std::cout << "endtest" << std::endl;
		*/

		std::vector<int> paths(n + m);
		int minw = mtA[0].w;
		int mini;
		for (int i = 0; i < n + m; i++) {
			if (mtA[i].w == minw) {
				paths[i] = 1;
			}
			else {
				mini = i;
				break;
			}
		}

		for (int i = mini; i < n + m; i++) {
			for (int j = 0; mtA[j].w != mtA[i].w; j++) {
				if (mtA[j].h < mtA[i].h) {
					paths[i] = max(paths[i], paths[j] + 1);
					//std::cout << "i:" << i << "j:" << j << " paths[i]:" << paths[i] << " paths[j]:" << paths[j] << std::endl;
				}
			}
		}
		int maxpath = 0;
		for (int i = 0; i < n + m ; i++ ) {
			maxpath = max(maxpath, paths[i]);
		}
		std::cout << maxpath << std::endl;

	} while (1);


	return 0;
}