Link to this code: https://cses.fi/paste/67853cbe6ac0a0cf269d22/
/*
  author: @ankingcodes
  created: 2021-07-17 22:54:27.285518
*/
        
#include<bits/stdc++.h>
#include<algorithm>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define MOD 1000000007

typedef tree<int, null_type, less<int>, rb_tree_tag,
                tree_order_statistics_node_update> PBDS;

typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
                tree_order_statistics_node_update> pairPBDS;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n; cin >> n;
  vector<pair<ll, ll>> a;
  for (int i=0;i<n;i++) {
    ll p, q; cin >> p >> q;
    a.push_back(make_pair(q, p));
  }
  sort(a.begin(), a.end());
  ll ans = 1;
  ll curr = a[0].first;
  for (ll i=1;i<n;i++) {
    if (a[i].second >= curr) {
      curr = a[i].first;
      ans+=1;
    }
  }
  cout << ans << endl;
  return 0;
}