#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

// Dinic
template<typename T>
struct Dinic {

    struct Graph {
        int to, rev;
        T cap;

        Graph(int t, int r, const T &c) : to(t), rev(r), cap(c) {};
    };

    vector<vector<Graph>> g;
    vector<int> level;
    vector<int> iter;
    int sz;

    Dinic(int N) : sz(N) {
        g.resize(N);
        iter.resize(N);
        level.resize(N);
    }

    void add_edge(int from, int to, T cap) {
        g[from].eb(to, (int) g[to].size(), cap);
        g[to].eb(from, (int) g[from].size() - 1, 0);
    }

    T operator()(int start, int end) {
        T flow = 0;
        while(true) {
            bfs(start);
            if (level[end] < 0) break;

            iter.assign(sz, 0);

            T f;
            while(f = dfs(start, end, inf) > 0) {
                flow += f;
            }
        }
        return flow;
    }

private:
    void bfs(int s) {
        level.assign(sz, -1);

        level[s] = 0;
        queue<int> q;
        q.push(s);

        while(!q.empty()) {
            int v = q.front(); q.pop();
            for(auto &e: g[v]) {
                int t = e.to;
                if (e.cap > 0 && level[t] < 0) {
                    level[t] = level[v] + 1;
                    q.push(t);
                }
            }

        }
    }

    T dfs(int v, int t, T flow) {
        if (v == t || flow == 0) return flow;

        for (int &i = iter[v]; i < g[v].size(); ++i) {
            auto &e = g[v][i];
            if(e.cap <= 0 || level[v] >= level[e.to]) continue;
            if (T f = dfs(e.to, t, min(flow, e.cap)) > 0) {
                e.cap -= f;
                g[e.to][e.rev].cap += f;
                return f;
            }
        }

        return 0;
    }
};

int greedy() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;

    int a[N], b[N];
    REP(i, N) cin >> a[i] >> b[i];

    set<int> p[N], q[N];

    REP(i, N) {
        int c, d;
        cin >> c >> d;

        REP(j, N) {
            if (a[j] < c && b[j] < d) {
                p[j].insert(i);
                q[i].insert(j);
            }
        }
    }

    set<int> op, oq;
    REP(i, N) {
        op.insert(i);
        oq.insert(i);
    }

    int ans = 0;
    REP(i, N) {
        int m = inf;
        int k = -1;
        for (auto e: op) {
            if (p[e].size() < m) {
                m = p[e].size();
                k = e;
            }
        }
        op.erase(k);

        if (p[k].size() < 1) continue;

        ++ans;

        m = inf;
        int l = -1;
        for (auto e: p[k]) {
            if (q[e].size() < m) {
                m = q[e].size();
                l = e;
            }
        }
        oq.erase(l);

        for (auto e: op) {
            p[e].erase(l);
        }

        for (auto e: oq) {
            q[e].erase(k);
        }
    }

    cout << ans << endl;
    return 0;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    int a[N], b[N];
    REP(i, N) cin >> a[i] >> b[i];

    Dinic<int> dnc(2 * N + 2);

    REP(i, N) {
        int c, d;
        cin >> c >> d;
        REP(j, N) {
            if (c > a[j] && d > b[j]) {
                dnc.add_edge(j, N + i, 1);
            }
        }
    }

    REP(i, N) {
        dnc.add_edge(2 * N, i, 1);
        dnc.add_edge(N + i, 2 * N + 1, 1);
    }

    print(dnc(2 * N, 2 * N + 1));

}


Measured memory_bytes: 384