const
maxnum=10000000;
var
n,m,i,j,vle,vri,vans:longint;
data:array[0..maxnum] of integer;
dause:array[0..1000] of boolean;
begin
assign(input,'ha14d.in');
reset(input);
assign(output,'ha14d.out');
rewrite(output);
readln(n,m);
fillchar(dause,sizeof(dause),false);
for i:=1 to m do
begin
readln(vle,vri);
for j:=vle to vri do
data[j]:=i;
dause[i]:=true;
end;
vans:=0;
for i:=1 to n do
begin
if (dause[data[i]]) then
inc(vans);
dause[data[i]]:=false;
end;
writeln(vans);
close(input);
close(output);
end.