#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;

/* typedef */
typedef long long ll;

/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* global variables */

/* function */

/* main */
int main(){
    int n, s, t;
    cin >> n;
    vector< pair< int, int> > times(n);
    for (int i = 0; i < n; i++) {
        cin >> s >> t;
        times[i] = make_pair(s, t);
    }
    sort(times.begin(), times.end());

    int ans = 0;
    int tail = NIL;
    for (int i = 0; i < n; i++) {
        s = times[i].first;
        t = times[i].second;
        if (t < tail) 
            tail = t;
        else if (tail < s) {
            ans++;
            tail = t;
        }
    }

    cout << ans << '\n';

}

