#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

template<typename flow_t>
struct Dinic{
    const flow_t INF;

    struct edge{
        int to;
        flow_t cap;
        int rev;
        edge(int to, flow_t cap, int rev) : to(to), cap(cap), rev(rev) {}
    };

    vector<vector<edge>> graph;
    vector<int> min_cost;       // sからの距離(bfsで調べる)
    vector<int> iter;           // どこまで調べ終わったか(dfs時に使用)

    Dinic(int V) : INF(numeric_limits<flow_t>::max()){
        graph.resize(V);
    }

    void add_edge(int from, int to, flow_t cap){
        graph[from].push_back(edge(to, cap, graph[to].size()));
        graph[to].push_back(edge(from, 0, graph[from].size() - 1));
    }

    bool bfs(int s, int t){
        min_cost.assign(graph.size(), -1);
        queue<int> que;
        min_cost[s] = 0;
        que.push(s);
        while(!que.empty() && min_cost[t] == -1){
            int p = que.front();
            que.pop();
            for(auto &e : graph[p]){
                if(e.cap > 0 && min_cost[e.to] == -1){
                    min_cost[e.to] = min_cost[p] + 1;
                    que.push(e.to);
                }
            }
        }
        return min_cost[t] != -1;
    }

    flow_t dfs(int v, int t, flow_t flow){
        if(v == t)  return flow;
        for(int &i = iter[v]; i < graph[v].size(); ++i){
            edge &e = graph[v][i];
            if(e.cap > 0 && min_cost[v] < min_cost[e.to]){
                flow_t d = dfs(e.to, t, min(flow, e.cap));
                if(d > 0){
                    e.cap -= d;
                    graph[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    flow_t max_flow(int s, int t){
        flow_t flow = 0;
        while(bfs(s, t)){
            iter.assign(graph.size(), 0);
            flow_t f = 0;
            while((f = dfs(s, t, INF)) > 0) flow += f;
        }
        return flow;
    }
};

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

    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n), d(n);
    Dinic<int> flow(2 * n + 2);
    int s = 0, t = 2 * n + 1;
    for(int i = 0; i < n; ++i){
        cin >> a[i] >> b[i];
        flow.add_edge(s, i + 1, 1);
    }
    for(int i = 0; i < n; ++i){
        cin >> c[i] >> d[i];
        flow.add_edge(n + i + 1, t, 1);
    }
    for(int i = 0; i < n; ++i){
        int u = i + 1;
        int rx = a[i], ry = b[i];
        for(int j = 0; j < n; ++j){
            int v = n + j + 1;
            int bx = c[j], by = d[j];
            if(rx < bx && ry < by)  flow.add_edge(u, v, 1);  
        }
    }
    cout << flow.max_flow(s, t) << "\n";
}

Measured memory_bytes: 384