#include using namespace std; using LL = long long; const int mxn = 2e5 + 10; int n; struct node { int R, r; bool operator < (const node &rhs) const { return R == rhs.R ? r > rhs.r : R > rhs.R; } } a[mxn]; multiset s; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i].r >> a[i].R; s.insert(a[i]); } int ans = -1; while (!s.empty()) { ++ans; node x = *begin(s); s.erase(begin(s)); for (auto it = s.lower_bound({ x.r, INT_MAX }); it != end(s);) { assert(x.r >= it -> R); // printf("x = (%d, %d), it = (%d, %d)\n", // x.R, x.r, it -> R, it -> r); x = *it; s.erase(it); it = s.lower_bound({ x.r, INT_MAX }); } } cout << ans << "\n"; return 0; }