program ex;
type
ss=array[1..10000]of longint;
sz=array[0..10000]of boolean;
var
f1,f2:text;
a,b:ss;
c,d:sz;
n,t:integer;
procedure init;
var
i,j,k:integer;
begin
assign(f1,'punch.in');
assign(f2,'punch.out');
reset(f1);
rewrite(f2);
readln(f1,n);
t:=n;i:=0;k:=0;
while not eof(f1) do
begin
inc(i);
readln(f1,a[i],b[i]);
if (c[a[i]]=false)and(d[b[i]]=false) then
begin
c[a[i]]:=true;
d[b[i]]:=true;
end
else if (c[a[i]]=true)and(d[b[i]]=true) then
begin
dec(i);
dec(t);
end;
k:=i;
for j:=1 to k-1 do
if (a[k]<=a[j])and(b[k]>=b[j]) then
begin
c[a[j]]:=false;
d[b[j]]:=false;
a[j]:=a[i];
b[j]:=b[i];
dec(i);
dec(t);
end;
end;
writeln(f2,t)
end;
begin
init;
close(f2);
end.