#include <bits/stdc++.h>
using namespace std;
long long int n;
long long int dp[1000000][2];
vector<pair<long long int, long long int> > a;
bool comp(pair<long long int, long long int> x,
          pair<long long int, long long int> y) {
  return x.second < y.second;
}
int main() {
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    a.push_back(make_pair(x, y));
  }
  sort(a.begin(), a.end(), comp);
  long long int ans = 0;
  long long int last = 0;
  for (long long int i = 0; i < n; i++) {
    if (a[i].first > last) {
      ans += 1;
      last = a[i].second;
    }
  }
  cout << ans;
}
