var ans,i,n,m,j:longint;
a,b:array[0..1000]of longint;
al:array[0..10000000]of integer;
procedure work;
var fi:longint;
begin
fi:=0;
fillchar(al,sizeof(al),0);
for i:=m downto 1 do
for j:=a[i] to b[i] do begin
if al[j]=0 then begin
inc(fi);al[j]:=i;
end;
if fi=n then exit;
end;
end;
procedure calc;
var ac:array[0..1000]of boolean;
begin
fillchar(ac,sizeof(ac),false);
for i:=1 to n do
ac[al[i]]:=true;
ans:=0;
for i:=1 to m do
if ac[i] then inc(ans);
end;
begin
assign(input,'ha14d.in');
assign(output,'ha14d.out');
reset(input);
rewrite(output);
readln(n,m);
for i:=1 to m do
read(a[i],b[i]);
work;
calc;
writeln(ans);
close(input);
close(output);
end.