import Data.List;main=do{n<-readLn;k<-q n;q n>>=print.f k};m=sortOn;q n=m fst<$>mapM(\_->map read.words<$>getLine>>= \[a,b]->pure(a::Int,b))[1..n];f u[]=0;f u((c,d):v)=case m snd[(a,b)|(a,b)<-u,a<=c,b<=d]of{[]->f u v;r->1+f(filter(/=last r)u)v}