#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; vector> rR(n); for (int i = 0; i < n; i++) { cin >> rR[i].first >> rR[i].second; } sort(rR.begin(), rR.end()); vector dp(n + 1, 2e9); dp[0] = 0; for (auto [r, R] : rR) { auto lb = lower_bound(dp.begin(), dp.end(), r + 1); if (*lb > R) { *lb = R; } } // for (int i = 0; i <= n; i++) { // cout << dp[i] << " "; // } // cout << endl; int ans = lower_bound(dp.begin(), dp.end(), 2e9) - dp.begin(); cout << n - ans + 1 << endl; }