program punch;
type
shuzu=array[0..100000000] of integer;
shuzu1=array[1..10000] of boolean;
var
s:shuzu;
f:shuzu1;
i,j,k,m,n,a,b,max,temp,c:longint;
begin
assign(input,'punch.in');reset(input);
assign(output,'punch.out');rewrite(output);
readln(n);
max:=0;
for i:=1 to n do
begin
readln(a,b);
if b>max then max:=b;
for j:=a+1 to b do
s[j]:=i;
end;
temp:=s[1]; f[s[1]]:=true;
c:=1;
for i:=1 to max do
begin
if (temp<>s[i])and(not f[s[i]])
then begin inc(c);temp:=s[i]; f[s[i]]:=true; end;
end;
writeln(c);
close(output);
end.