#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
mt19937 rng(1);
const int mxn = 5e3+5;
int n;
int l[mxn], r[mxn];
bitset<mxn> adj[mxn],used;
int mt[mxn];
bool kuhn(int v) {
used.reset(v);
bitset<mxn> nx = adj[v];
nx &= used;
for (int i=nx._Find_first(); i < nx.size(); i = nx._Find_next(i)) {
vis.reset(i);
if (mt[i]==-1 || kuhn(mt[i])) {
mt[i] = v;
return 1;
}
nx &= used;
}
return 0;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin>>n;
for (int i=0; i<n; i++) {
cin>>l[i]>>r[i];
adj[i].reset();
}
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
if (l[i] < l[j] && r[i] > l[j] && r[i] < r[j])
adj[j].set(i);
}
}
memset(mt,-1,sizeof(mt));
for (int v=0; v<n; v++) {
used.set();
kuhn(v);
}
int cnt = 2*n;
for (int i=0; i<n; i++) {
if (mt[i] != -1) {
cnt--;
}
}
cout<<cnt;
return 0;
}