#include <bits/stdc++.h>
typedef long long ll;
#define mod
#define MAX
#define pb push_back
#define mp make_pair
#define pr pair<int,int>
using namespace std;
int n;
vector<pr >v(100005);
int lessthan(pr a,pr b)
{
if(a.first<b.first && a.second<b.second)
return 1;
return 0;
}
int CeilIndex(vector<pr >tailTable,int low,int high,pr key)
{
while(low<high)
{
int mid=low+(high-low)/2;
if(lessthan(tailTable[mid],key))
low=mid+1;
else
high=mid;
}
return low;
}
int lis()
{
vector<pr >tailTable(100005);
int len=1;
tailTable[0]=v[0];
for(int i=1;i<n;i++)
{
if(lessthan(v[i],tailTable[0]))
tailTable[0]=v[i];
else if(lessthan(tailTable[len-1],v[i]))
tailTable[len++]=v[i];
else
{
tailTable[CeilIndex(tailTable,0,len-1,v[i])]=v[i];
}
}
return len;
}
int main()
{
scanf("%d",&n);
int i,a,b;
for(i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
v[i]=mp(a,b);
}
printf("%d\n",lis());
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnR5cGVkZWYgbG9uZyBsb25nIGxsOwojZGVmaW5lIG1vZAojZGVmaW5lIE1BWAojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIG1wIG1ha2VfcGFpcgojZGVmaW5lIHByIHBhaXI8aW50LGludD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbjsKdmVjdG9yPHByID52KDEwMDAwNSk7CgppbnQgbGVzc3RoYW4ocHIgYSxwciBiKQp7CglpZihhLmZpcnN0PGIuZmlyc3QgJiYgYS5zZWNvbmQ8Yi5zZWNvbmQpCgkJcmV0dXJuIDE7CglyZXR1cm4gMDsKfQoKaW50IENlaWxJbmRleCh2ZWN0b3I8cHIgPnRhaWxUYWJsZSxpbnQgbG93LGludCBoaWdoLHByIGtleSkKewoJd2hpbGUobG93PGhpZ2gpCgl7CgkJaW50IG1pZD1sb3crKGhpZ2gtbG93KS8yOwoJCWlmKGxlc3N0aGFuKHRhaWxUYW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