#include using namespace std; #include using namespace atcoder; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; ++i) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> n; vector> a(n); rep(i,n) cin >> a[i].first >> a[i].second; sort(all(a)); segtree dp(n+1); rep(i,n){ int x = lower_bound(all(a), make_pair(a[i].second,0)) - a.begin(); dp.set(x, max(dp.prod(0,i+1)+1, dp.get(i+1))); } cout << n-dp.get(n) << '\n'; return 0; }