#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<double, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v, int idx)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        if (i == idx)
        {
            cout << "[" << v[i] << "]"
                 << " \n"[i == sz - 1];
            continue;
        }
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<P> v(n);
    for (int i = 0; i < n; i++)
    {
        int s, t;
        cin >> s >> t;
        v[i] = P(t, s);
    }
    sort(v.begin(), v.end());
    int res = 0, gt = 0;
    for (int i = 0; i < n; i++)
    {
        if (gt < v[i].second)
        {
            res++;
            gt = v[i].first;
        }
    }
    cout << res << endl;
}
