Link to this code: https://cses.fi/paste/eba86de0b40b8dfa1b4b2f/
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define debo(x) cout << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
#define rem(s,ch)  s.erase(std::remove(s.begin(), s.end(), ch),s.end());
#define tosmall(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tobig(s) transform(s.begin(),s.end(),s.begin(),::toupper);

bool sortbysecinc( pair<ll int,ll int> &a,
                   pair<ll int,ll int> &b)
{
       return a.second<=b.second;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll int t, n, i, a, b;
    cin >> t;
    vector <pair<ll int, ll int> > v;
    while (t--) {
        cin >> a >> b;
        v.pb(mp(a,b));
    }
    ll int best = 0, sum = 0,counto=0;
    sort(all(v), sortbysecinc );
    ll int lasttime = 0;
    vector <pair<ll int, ll int> > :: iterator itr;
    for(itr = v.begin();itr!=v.end();itr++){
        if(lasttime <= (*itr).first){
            counto++;
            lasttime = (*itr).second;
        }
        
    }

    // cout << "  --- " << endl;

    // for(itr = v.begin();itr!=v.end();itr++){
    //     deb2((*itr).first,(*itr).second);
    // }
    
    debo(counto);
    return 0;
}