#include <iostream>
using namespace std;
typedef long long ll;
ll n,id,l,r,m;
pair<ll,ll>p[100001],lis[100001];
int main()
{
cin>>n;
for(ll i = 1;i<=n;++i)
cin>>p[i].first>>p[i].second;
lis[id++] = p[1];
for(ll i = 2;i<=n;++i){
if(p[i].first < lis[0].first && p[i].second < lis[0].second)
lis[0] = p[i];
else if(p[i].first > lis[id-1].first && p[i].second > lis[id-1].second)
lis[id++] = p[i];
else{
l = 0;
r = id-1;
while(r > l+1){
m = (l+r)/2;
if(p[i].first < lis[m].first && p[i].second < lis[m].second)
r = m;
else
l = m;
}
lis[r] = p[i];
}
}
cout<<id<<endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKbGwgbixpZCxsLHIsbTsKcGFpcjxsbCxsbD5wWzEwMDAwMV0sbGlzWzEwMDAwMV07CmludCBtYWluKCkKewoJY2luPj5uOwoKCWZvcihsbCBpID0gMTtpPD1uOysraSkKCQljaW4+PnBbaV0uZmlyc3Q+PnBbaV0uc2Vjb25kOwoKCWxpc1tpZCsrXSA9IHBbMV07CgoJZm9yKGxsIGkgPSAyO2k8PW47KytpKXsKCQlpZihwW2ldLmZpcnN0IDwgbGlzWzBdLmZpcnN0ICYmIHBbaV0uc2Vjb25kIDwgbGlzWzBdLnNlY29uZCkKCQkJbGlzWzBdID0gcFtpXTsKCQllbHNlIGlmKHBbaV0uZmlyc3QgPiBsaXNbaWQtMV0uZmlyc3QgJiYgcFtpXS5zZWNvbmQgPiBsaXNbaWQtMV0uc2Vjb25kKQoJCQlsaXNbaWQrK10gPSBwW2ldOwoJCWVsc2V7CgoJCQlsID0gMDsKCQkJciA9IGlkLTE7CgoJCQl3aGlsZShyID4gbCsxKXsKCQkJCW0gPSAobCtyKS8yOwoKCQkJCWlmKHBbaV0uZmlyc3QgPCBsaXNbbV0uZmlyc3QgJiYgcFtpXS5zZWNvbmQgPCBsaXNbbV0uc2Vjb25kKQoJCQkJCXIgPSBtOwoJCQkJZWxzZQoJCQkJCWwgPSBtOwoJCQl9CgoJCQlsaXNbcl0gPSBwW2ldOwoJCX0KCX0KCgljb3V0PDxpZDw8ZW5kbDsKfQ==