Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"sort"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		hr := make([]entry, 0)
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			first, _ := strconv.Atoi(buf[0])
			second, _ := strconv.Atoi(buf[1])
			mt := entry{first, second}
			hr = append(hr, mt)
		}
		scanner.Scan()
		m, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < m; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			first, _ := strconv.Atoi(buf[0])
			second, _ := strconv.Atoi(buf[1])
			mt := entry{first, second}
			hr = append(hr, mt)
		}
		sort.Sort(ByFirst(hr))
		fmt.Println(LIS(hr))
	}
}

type entry struct {
	first, second int
}

type ByFirst []entry

func(f ByFirst) Len() int {
	return len(f)
}

func (f ByFirst) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}

func (f ByFirst) Less(i, j int) bool {
	return f[i].first < f[j].first
}

func LIS(hr []entry) int {
	n := len(hr)
	lis := make([]int, n)
	lis[n-1] = 1
	for i := n-2; i > -1; i-- {
		m := 0
		for j := i+1; j < n; j++ {
			if hr[i].first < hr[j].first && hr[i].second < hr[j].second && lis[j] > m {
				m = lis[j]
			}
		}
		lis[i] = m+1
	}
	return lis[0]
}

C++: #include <bits/stdc++.h>

#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VVVVI vector<vector<vector<vector<int>>>>
#define VL vector<LL>
#define VVL vector<vector<LL>>
#define VVVL vector<vector<vector<LL>>>
#define VVVVL vector<vector<vector<vector<LL>>>>
#define VB vector<bool>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

template<class T> T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> void print(T x) { std::cout << x << std::endl; }

const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy = { 0, -1, 0, 1 }, dx = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）

using namespace std;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    while (true) {
        int N, M;
        cin >> N;
        if (N == 0) { break; }

        vector<pair<int, int>> v;
        FOR(i, 0, N) {
            int h, r;
            cin >> h >> r;
            v.emplace_back(make_pair(h, r));
        }
        cin >> M;
        FOR(i, 0, M) {
            int h, r;
            cin >> h >> r;
            v.emplace_back(make_pair(h, r));
        }
        sort(ALL(v));

        VVI dp(v.size() + 1, VI(v.size(), -1));
        dp[0][0] = 1;

        FOR(i, 0, v.size()) {
            int h1 = v[i].first, r1 = v[i].second;

            FOR(j, 0, dp[0].size()) {
                if (dp[i][j] != -1) {

                    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);

                    int h2 = v[j].first, r2 = v[j].second;
                    if (h2 < h1 and r2 < r1) {
                        dp[i + 1][i] = max(dp[i + 1][i], dp[i][j] + 1);
                    }
                }
            }
        }

        print(MAX(dp[v.size()]));
    }

    return 0;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
vint dp;
vector<pii> v;
int foo(int c){
	if(dp[c]>=0) return dp[c];
	int ret=1;
	rep(i,v.size()){
		if(v[c].F<v[i].F&&v[c].S<v[i].S){
			ret=max(ret,foo(i)+1);
		}
	}
	return dp[c]=ret;
}

void mainmain(){
	int n,m;
	while(cin>>n,n){
		v.clear();
		rep(i,n){
			int a,b;
			cin>>a>>b;
			v.PB(mkp(a,b));
		}
		cin>>m;
		rep(i,m){
			int a,b;
			cin>>a>>b;
			v.PB(mkp(a,b));
		}
		dp=vint(n+m,-1);
		rep(i,v.size()){
			foo(i);
		}
		int ans=0;
		rep(i,n+m){
			ans=max(ans,dp[i]);
		}
		cout<<ans<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

C++: #include <iostream>

using namespace std;

int n, m;
int d[200][2], dp[200];

int main(){
    for(;;){
        if(cin >> n){
            for(int i = 0; i < 200; i++){
                dp[i] = 0;
            }
            if(n == 0){
                break;
            }
            for(int i = 0; i < n; i++){
                cin >> d[i][0] >> d[i][1];
                for(int j = i; j > 0; j--){
                    if(d[j][0] > d[j - 1][0]){
                        break;
                    }else{
                        int a = d[j][0];
                        int b = d[j][1];
                        d[j][0] = d[j - 1][0];
                        d[j][1] = d[j - 1][1];
                        d[j - 1][0] = a;
                        d[j - 1][1] = b;
                    }
                }
            }
            cin >> m;
            for(int i = n; i < n + m; i++){
                cin >> d[i][0] >> d[i][1];
                for(int j = i; j > 0; j--){
                    if(d[j][0] > d[j - 1][0]){
                        break;
                    }else{
                        int a = d[j][0];
                        int b = d[j][1];
                        d[j][0] = d[j - 1][0];
                        d[j][1] = d[j - 1][1];
                        d[j - 1][0] = a;
                        d[j - 1][1] = b;
                    }
                }
            }
            int max = 0;
            for(int i = 0; i < n + m; i++){
                dp[i]++;
                int a = 0;
                for(int j = 0; j < i; j++){
                    if(a <= dp[j]&&d[j][1] < d[i][1]){
                        a = dp[j];
                    }
                }
                dp[i] += a;
                if(max <= dp[i]){
                    max = dp[i];
                }
            }
            cout << max << endl;
        }else{
            break;
        }
    }
    return 0;
}