#include using namespace std; #define llong long long int #define ldouble long double #define rep(i, n) for (int i = 0; i < n; ++i) #define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr) #define stl_repr(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() const static int MOD = 1000000000 + 7; const static int inf = INT_MAX / 2; const static llong INF = 1LL << 31; const static int dx[] = {1, 0, -1, 0}; const static int dy[] = {0, 1, 0, -1}; int main (int argc, char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector L(n), R(n), dp; rep(i, n) cin >> L[i] >> R[i]; dp.push_back(L[0]); for (int i = 1; i < n; ++i) { if (L[i] > dp.back()) { dp.push_back(L[i]); } else { if (R[i] <= dp.back()) { *lower_bound(all(dp), L[i]) = L[i]; } else { dp.push_back(dp.back() + 1); } } } cout << dp.size() << endl; return 0; }