#include<iostream>
#include<map>
using namespace std;

 map<int, pair<int,int> > m1;
 map<int, pair<int,int> > :: iterator it;
 
 int p;
 
int find_pos(int ar[], int low, int high, int curr)
{
	p=-1;
	int mid;
	while(low<high)
	{
	 mid= (low+high)/2;
	if(m1[mid].first <= m1[curr].first && m1[mid].second<=m1[curr].second)
	 {
	 	low=mid+1;
	 	p=low;
	 }
	else if(m1[mid].first >= m1[curr].first && m1[mid].second>=m1[curr].second)
	 {
	 	high=mid-1;
	 	p=high;
	 }
	
	}
	
	if(p==-1)
	 return mid;
	else return p;
}

int main()
{
int n,minx=1000000000,miny=1000000000,pos;
cin>>n;
int c[n+1],cnt=0;
int x,y,i;
for(i=0;i<n;i++)
{
cin>>x>>y;
if(x<=minx)
{
minx=x;
if(y<miny) {
	miny=y;
	pos=i;
}
}
m1.insert(pair<int, pair<int,int> >(i, make_pair(x, y)));
}
/*
cout<<"the entry with least value is "<<minx<<" "<<miny<<"at position "<<pos<<endl;

cout<<"The map has entries\n";

for(i=0;i<n;i++)
{
	cout<<m1[i].first<<" "<<m1[i].second<<endl;
}
*/

i=0;
int sz=0;
c[sz]=pos;
while(i<n)
{
   if(i==pos) i++;
   
   if(m1[i].first>=m1[c[sz]].first && m1[i].second>=m1[c[sz]].second)
   {
     sz=sz+1;
     cnt++;
     c[sz]=i;
   }
   else if(m1[i].first<=m1[c[sz]].first && m1[i].second<=m1[c[sz]].second)
   {
   int p = find_pos(c,0,sz,i);
    if(p!=-1) // indicates that the element can be inserted in the array
    {
      if(m1[c[p]].first<m1[i].first && m1[c[p]].second< m1[i].second)
       p=p+1;
      c[p]=i;
    }
   }
   i++;
}

cout<<cnt<<endl;
//cout<<"length of lis is "<<cnt<<endl;

return 0;
}