#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cmath>
#include<stack>
#include<set>
#include<queue>
#include<string>
#include<iostream>
#include<map>
#include<cstdlib>
#include<ctime>
using namespace std;
//freopen("in.txt","r",stdin); FILE-IO
//fclose(stdin); FILE-IO
//srand (time(NULL)); RANDOM NUMBERS
#define M_PI 3.14159265358979323846 /* pi */
#define _USE_MATH_DEFINES
#define db(a) printf("check%d\n",(a))
#define dbg(a,b) printf("check%d %d\n",(a),(b))
#define sd(a) scanf("%d",&a)
#define pd(a) prlong longf("%lld\n",(a))
#define clr(a) memset(a,0,sizeof(a))
#define LL long long
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LIM 200000
set<int> s[LIM];
map<int,int> comp1;
map<int,int> comp[LIM];
vector<int> bit[LIM];
pair<int,int> a[LIM];
pair<int,int> a1[LIM];
set<int> temp;
int cnt1;
int cnt[LIM];
int query1(int i,int idx)
{
int ret=0;
while(idx)
{
ret=max(ret,bit[i][idx]);
idx=idx-(idx&(-idx));
}
return ret;
}
int query(int idx,int val)
{
int ret=0;
while(idx)
{
map<int,int>::iterator it=comp[idx].lower_bound(val);
int pos;
if(it==comp[idx].end())
pos=cnt[idx];
else
pos=(*it).S-1;
//int pos=(*(comp[idx].lower_bound(val))).S;
//if(pos==0)
// pos=cnt[idx];
//else
// --pos;
ret=max(ret,query1(idx,pos));
idx=idx-(idx&(-idx));
}
return ret;
}
void update1(int i,int idx,int val)
{
while(idx<=cnt[i])
{
bit[i][idx]=max(bit[i][idx],val);
idx=idx+(idx&(-idx));
}
}
void update(int val1,int idx,int val)
{
while(idx<=cnt1)
{
//db(11);
int pos=comp[idx][val];
//dbg(val,pos);
update1(idx,pos,val1);
idx=idx+(idx&(-idx));
}
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,i,j,k,x,y,ans=0;
cnt1=0;
//db(1);
for(i=0;i<LIM;++i)
cnt[i]=0;
//db(2);
sd(n);
for(i=0;i<n;++i)
{
//db(3);
sd(x);
sd(y);
a[i]=MP(x,y);
a1[i]=MP(x,y);
}
sort(a1,a1+n);
for(i=0;i<n;++i)
{
if(!comp1[a1[i].F])
comp1[a1[i].F]=++cnt1;
s[comp1[a1[i].F]].insert(a1[i].S);
}
//db(4);
for(i=1;i<=cnt1;++i)
{
//db(5);
temp.clear();
for(j=i;j>(i-(i&(-i)));--j)
{
//db(6);
set<int>::iterator it=s[j].begin();
for(;it!=s[j].end();++it)
{
//db(7);
//int val=*it;
temp.insert(*it);
//if(!comp[i][val])
//{
// comp[i][val]=++cnt[i];
//}
}
}
set<int>::iterator it=temp.begin();
for(;it!=temp.end();++it)
{
comp[i][*it]=++cnt[i];
}
bit[i].resize(cnt[i]+1,0);
}
for(i=0;i<n;++i)
{
int ans1=1+query(comp1[a[i].F]-1,a[i].S);
ans=max(ans,ans1);
update(ans1,comp1[a[i].F],a[i].S);
}
//for(i=0;i<n;++i)
//{
// printf("%d %d\n",a1[i].F,comp1[a1[i].F]);
//}
printf("%d",ans);
}
I2luY2x1ZGU8Y3N0ZGlvPgojaW5jbHVkZTxhbGdvcml0aG0+CiNpbmNsdWRlPHZlY3Rvcj4KI2luY2x1ZGU8Y3N0cmluZz4KI2luY2x1ZGU8Y21hdGg+CiNpbmNsdWRlPHN0YWNrPgojaW5jbHVkZTxzZXQ+CiNpbmNsdWRlPHF1ZXVlPgojaW5jbHVkZTxzdHJpbmc+CiNpbmNsdWRlPGlvc3RyZWFtPgojaW5jbHVkZTxtYXA+CiNpbmNsdWRlPGNzdGRsaWI+CiNpbmNsdWRlPGN0aW1lPiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8vZnJlb3BlbigiaW4udHh0IiwiciIsc3RkaW4pOwlGSUxFLUlPIAovL2ZjbG9zZShzdGRpbik7CQlGSUxFLUlPCi8vc3JhbmQgKHRpbWUoTlVMTCkpOwkJUkFORE9NIE5VTUJFUlMKCiNkZWZpbmUgTV9QSSAzLjE0MTU5MjY1MzU4OTc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