#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
#define PII pair<int,int>
vector<PII> V;
int n;
int main()
{
cin>>n;
int u,v;
for(int i = 1;i <= n; ++i)
{
cin>>u>>v;
V.push_back({v,u});
}
sort(V.begin(),V.end());
int loc = V[0].first;
int ans = 1;
for(int i = 1;i < n; ++i)
{
if(loc >= V[i].second) continue;
ans++;loc = V[i].first;
}
cout<<ans<<endl;
return 0;
}