#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

const int INF = (int)1e9;

struct Edge {
  int to, cap, rev;
  Edge(int to_, int cap_, int rev_) :
    to(to_), cap(cap_), rev(rev_) { }
};

struct FordFulkerson {
  const int V;
  vector<vector<Edge> > G;
  vector<bool> used;
  FordFulkerson(int v) : V(v), G(v), used(v) { }
  void add_edge(int from, int to, int cap) {
    G[from].emplace_back(to, cap, G[to].size());
    G[to].emplace_back(from, 0, G[from].size() - 1);
  }
  int find_flow(int v, int t, int f) {
    if(v == t) return f;
    used[v] = true;
    for(Edge &e : G[v]) {
      if(used[e.to] == false && e.cap > 0) {
        int d = find_flow(e.to, t, min(f, e.cap));
        if(d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  int max_flow(int s, int t) {
    int flow = 0;
    while(true) {
      used.assign(V, false);
      int f = find_flow(s, t, INF);
      if(f == 0) return flow;
      flow += f;
    }
  }
};

int main() {
  int N; cin >> N;
  vector<int> W(N);
  vector<int> H(N);
  for(int i = 0; i < N; ++i) {
    cin >> W[i] >> H[i];
    if(H[i] > W[i]) swap(H[i], W[i]);
  }
  FordFulkerson flow(2*N+2);
  for(int i = 0; i < N; ++i) {
    flow.add_edge(2*N, i, 1);
    flow.add_edge(N + i, 2*N + 1, 1);
    for(int j = 0; j < N; ++j) {
      if(W[i] > W[j] && H[i] > H[j])
        flow.add_edge(i, N + j, 1);
    }
  }
  cout << (N - flow.max_flow(2*N, 2*N+1)) << endl;
}
