#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,ans;
int main()
{
	cin>>n;
	vector<pair<int,int> >a;
	int now=0;
	for(int i=0;i<n;i++)
	{
		int x,y;cin>>x>>y;
		a.push_back(make_pair(y,x));
	}
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++)
	{
		if(now<a[i].second)
		{
			ans++;
			now=a[i].first;
		}
	}
	cout<<ans<<endl;
}

