#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include<iostream>
#include<cmath>

struct Doll {
	int height, radius;
	bool can_wrap(const Doll that) const {
		return height > that.height && radius > that.radius;
	}
};
int max_size(int current, const std::vector<std::vector<int>>& prev, std::vector<int>& memo) {
	if (memo[current] >= 0) return memo[current];
	if (prev[current].empty()) return 1;
	int max = 0;
	for (const auto p : prev[current]) {
		max = std::max(max, max_size(p, prev, memo) + 1);
	}
	return memo[current] = max;
}
int main() {
	while (true) {
		int n; std::cin >> n; if (n == 0) break;
		std::vector<Doll> dolls;
		for (auto i = 0; i < n; ++i) {
			int height, radius; std::cin >> height >> radius;
			dolls.push_back(Doll{ height, radius });
		}
		int m; std::cin >> m;
		for (auto i = 0; i < m; ++i) {
			int height, radius; std::cin >> height >> radius;
			dolls.push_back(Doll{ height, radius });
		}
		std::vector<std::vector<int>> prev(n + m);
		for (auto i = 0; i < n; ++i) {
			if (i != n - 1) prev[i + 1].push_back(i);
			for (auto j = n; j < n + m; ++j) if (dolls[j].can_wrap(dolls[i])) {
				prev[j].push_back(i);
			}
		}
		for (auto i = n; i < n + m; ++i) {
			if (i != n + m - 1) prev[i + 1].push_back(i);
			for (auto j = 0; j < n; ++j) if (dolls[j].can_wrap(dolls[i])){
				prev[j].push_back(i);
			}
		}
		std::vector<int> memo(n + m, -1);
		std::cout << std::max(max_size(n - 1, prev, memo), max_size(n + m - 1, prev, memo)) << '\n';
	}
}
