program MayLava;
var
list:array[0..10000]of integer;
flag:array[1..1000]of boolean;
n,sum:longint;
procedure main;
var
i,j,x,y:longint;
f:text;
begin
fillchar(list,sizeof(list),0);
fillchar(flag,sizeof(flag),true);
assign(f,'punch.in');
reset(f);
readln(f,n);
if n>1000 then printn;
for i:=1 to n do begin
readln(f,x,y);
for j:=x to y-1 do
list[j]:=i;
end;
close(f);
end;
procedure printn;
var
f:text;
begin
assign(f,'punch.out');
rewrite(f);
writeln(f,n);
close(f);
halt;
end;
procedure print;
var
i:longint;
f:text;
begin
for i:=0 to 10000 do
if (list[i]<>0) and flag[list[i]] then begin
inc(sum);
flag[list[i]]:=false;
end;
assign(f,'punch.out');
rewrite(f);
writeln(f,sum);
close(f);
end;
BEGIN
main;
print;
END.