program mengyalan;
const
maxn=100000;
var
i,j:longint;
fi,fo:text;
axis:array[1..maxn] of integer;
k:array[1..10000] of boolean;
c1,c2:longint;
n,m,sum:integer;
begin
assign(fi,'punch.in');
assign(fo,'punch.out');
reset(fi);
rewrite(fo);
readln(fi,n);
fillchar(k,sizeof(k),false);
fillchar(axis,sizeof(axis),0);
m:=0; sum:=0;
for i:=1 to n do begin
readln(fi,c1,c2);
if c2>m then m:=c2;
for j:=c1 to c2 do axis[j]:=i;
end;
for i:=1 to m do
if (axis[i]>0)and(not(k[axis[i]])) then
k[axis[i]]:=true;
for i:=1 to n do if k[i] then inc(sum);
write(fo,sum);
close(fi);
close(fo);
end.