#include <bits/stdc++.h> using namespace std; #define all(v) (v).begin(),(v).end() #define pb(a) push_back(a) #define rep(i, n) for(int i=0;i<n;i++) #define foa(e, v) for(auto& e : v) using ll = long long; const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60); #define dout(a) cout<<fixed<<setprecision(10)<<a<<endl; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vector<ll> a(n), b(n); vector<pair<ll, ll>> v; rep(i, n) { cin >> a[i] >> b[i]; v.push_back({a[i], b[i]}); } sort(all(v)); multiset<ll> ms; foa(e, v) ms.insert(e.first); ll ans = 0; for(auto [x, y] : v) { auto itr = ms.lower_bound(y); if(itr == ms.end()) ans ++; else ms.erase(itr); } cout << ans - 1<< endl; return 0; }