#include 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; vector a(n), b(n); vector> v; rep(i, n) { cin >> a[i] >> b[i]; v.push_back({a[i], b[i]}); } sort(all(v)); multiset 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; }