#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
pair<int, int> r_l[maxn];
int n, t, ans;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> r_l[i].second >> r_l[i].first, r_l[i].second *= -1;
  sort(r_l, r_l + n);
  for (int i = 0; i < n; i++) {
    if (r_l[i].second * (-1) > t) t = r_l[i].first, ans++;
  }
  cout << ans;
  return 0;
}
