#include <bits/stdc++.h>
using namespace std;
bool cmp(const pair<int, int>& lhs, const pair<int, int>& rhs) {
  return lhs.second < rhs.second;
}
int main() {
  int n;
  cin >> n;
  pair<int, int> a[500001];
  for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
  sort(a, a + n, cmp);
  int ans = 0, cur = 0;
  for (int i = 0; i < n; i++)
    if (a[i].first > cur) ans++, cur = a[i].second;
  cout << ans;
  return 0;
}
