#include using namespace std; #define int long long #define x first #define y second #define pb push_back #define eb emplace_back #define v vector #define printv(a, x) for (int i = x; i < a.size(); i ++ ) \ cout << a[i] << " \n"[i == (int)a.size() - 1] #define printvv(a, x) for (int i = x; i < a.size(); i ++ ) \ for (int j = x; j < a[i].size(); j ++ ) \ cout << a[i][j] << " \n"[j == (int)a[i].size() - 1] #define all(x) (x).begin(), (x).end() #define readv(a, n, x) for (int i = x; i < n + x; i ++ ) \ cin >> a[i] #define readvv(a, n, m, x) for (int i = x; i < n + x; i ++ ) \ for (int j = x; j < m + x; j ++ ) \ cin >> a[i][j] #define gt greater #define pq priority_queue #define umap unordered_map #define uset unordered_set #define lbound(a, l, r, x) lower_bound(a.begin() + l, a.begin() + r + 1, x) - a.begin() #define ubound(a, l, r, x) upper_bound(a.begin() + l, a.begin() + r + 1, x) - a.begin() #define printd(x, d) cout << fixed << setprecision(d) << (x) << '\n' #define ne_per(a) next_permutation((a).begin(), (a).end()) template void base_dbg (const std::string& key, const T& value) { std::cerr << key << " = " << value; } template void dbg_args (const std::string& keys, Args... args) { size_t pos{ 0 }; ( (base_dbg (keys.substr (pos, keys.find (',', pos) - pos), args), pos = keys.find (',', pos) + 1), ...); } #define dbg(...) { \ std::cerr << ""; \ dbg_args(#__VA_ARGS__, __VA_ARGS__); \ std::cerr << '\n'; \ } template void base_print (const T& value) { std::cout << value << ' '; } template void print_args (Args... args) { size_t pos{ 0 }; ( (base_print (args) ), ...); } #define print(...) { \ std::cout << ""; \ print_args(__VA_ARGS__); \ std::cout << '\n'; \ } using i64 = long long; using u64 = unsigned long long; using u32 = unsigned int; using i128 = __int128; std::mt19937 rnd (std::chrono::steady_clock().now().time_since_epoch().count() ); constexpr int dx[] = {0, 0, 1, -1}; constexpr int dy[] = {1, -1, 0, 0}; void solve() { int n; cin >> n; vector f; for (int i = 0; i < n; i++) { int l, r; cin >> l >> r; auto it = lower_bound(f.begin(), f.end(), r); if (it != f.end()) { if (it != f.begin()) { l = max(l, *prev(it) + 1); } *it = l; } else { if (f.size()) { l = max(l, *prev(it) + 1); } f.push_back(l); } } cout << f.size(); } signed main() { ios_base::sync_with_stdio (false); cin.tie (nullptr); cout.tie (nullptr); int t = 1; // cin >> t; while (t -- ) solve(); return 0; }