#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
const int MAXN = 1e4 + 7;
ll n;
pair <ll, ll> a[MAXN];
vector <ll> f;

void solve(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i].fi >> a[i].se;
        if(a[i].fi > a[i].se) swap(a[i].fi, a[i].se);
    }
    sort(a + 1, a + 1 + n, [&](pair<ll,ll> x, pair<ll,ll> y) {
        return x.se < y.se;
    });
    
    for(int i = 1; i <= n; i++){
        auto it = lower_bound(f.begin(), f.end(), a[i].fi);
        if(it == f.end()) f.pb(a[i].fi);
        else *it = a[i].fi;
    }
    cout << f.size();
}

int main(){
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    // freopen("box.inp", "r", stdin); freopen("box.out", "w", stdout);
    solve();
}
