#include using namespace std; using LL = long long; using ULL = unsigned long long; using PII = pair; using PLI = pair; using PIL = pair; using PLL = pair; string text_yes, text_no; void set_yes_no_all_lower() { text_yes = "yes"; text_no = "no"; } void set_yes_no_all_upper() { text_yes = "YES"; text_no = "NO"; } void set_yes_no_first_upper_other_lower() { text_yes = "Yes"; text_no = "No"; } void yes() { cout << text_yes << endl; } void no() { cout << text_no << endl; } template struct is_iterable : false_type {}; template struct is_iterable())), decltype(end(declval()))>> : true_type {}; template enable_if_t::value && !is_same_v, istream&> operator>>(istream& in, T& value) { for (auto& i : value) { in >> i; } return in; } bool solve(int); int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); set_yes_no_all_lower(); set_yes_no_all_upper(); set_yes_no_first_upper_other_lower(); int T = 1; // cin >> T; for (int t = 1; t <= T && solve(t); ++t) { } return 0; } #define lson (k << 1) #define rson (k << 1 | 1) const int mod = 7 + 1e9; // const int mod = 998244353; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, -1, 1}; #if LEMON const int N = 3 + 256; #else #define endl '\n' const int N = 3 + 5e5; #endif bool solve(int case_id) { int n; cin >> n; map dp; dp[0] = 0; while (n--) { int l, r; cin >> l >> r; auto ndp = dp; for (auto [u, v] : ndp) { if (r > v) { int p = max(v + 1, l); if (!dp.count(u + 1)) { dp[u + 1] = 1e9; } dp[u + 1] = min(dp[u + 1], p); } } } cout << dp.size() - 1; return true; }