Link to this code: https://cses.fi/paste/5918be0fd61312f3180d1e/
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<stack>
#include<queue>
//#define int long long
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

bool compare(const pair<int, int>& a, const pair<int, int>& b){
    if(a.second <= b.second) return true;
    return false;
}

pair<int, int> arr[200001];

void solve(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++) cin >> arr[i].first >> arr[i].second;
    sort(arr, arr+n, compare); 
    int ans = 1;
    int curr = 0;
    for(int i=1;i<n;i++){
        if(arr[i].first >= arr[curr].second){ ans++; curr = i;}
    }
    cout << ans;
}

signed main(){
    FIO;
    int t=1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}