#include<bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;
typedef pair<int, int> P;

#define MAX 100005
#define INF 1001001001

int main(int, char**)
{
  int n;
  cin >> n;

  vector<P> times;
  rep(i,n) {
    int s, t;
    cin >> s >> t;
    times.emplace_back(s,t);
  }
  sort(times.begin(), times.end(), [&](P a, P b)->bool{ return a.second < b.second; });
  int ans = 0;
  int now = 0;
  rep(i,n) {
    int s, t;
    tie(s,t) = times[i];
    if (now < s) { ++ans; now = t; }
  }
  cout << ans << endl;

  return 0;
}

