program punch;
type
t1=array[0..100000] of longint;
t2=array[1..10000] of longint;
var
n,max,max1:longint;
x:t1;
color:t2;
procedure init;
begin
assign(input,'punch.in');
reset(input);
assign(output,'punch.out');
rewrite(output);
readln(n);
max:=0;
end;
function judge(w:longint):boolean;
var
i:longint;
begin
judge:=false;
for i:=1 to max1 do if w=color[i] then exit(true);
end;
procedure main;
var
i,j,x1,y1:longint;
begin
for i:=1 to n do
begin
readln(x1,y1);
if y1>=max then max:=y1;
for j:=x1 to y1 do x[j]:=i;
end;
for i:=1 to max do
if (not judge(x[i])) then
begin
inc(max1);
color[max1]:=x[i];
end;
end;
procedure print;
begin
writeln(max1);
close(input);
close(output);
end;
begin
init;
main;
print;
end.