program cojs1682;
var
a,b,i,j,k,m,n,ans:longint;
z,x:array[1..10000000] of longint;
begin
assign(input,'ha14d.in');
assign(output,'ha14d.out');
reset(input);
rewrite(output);
readln(n,m);
for i:=1 to m do
begin
readln(a,b);
for j:=a to b do
z[j]:=i;
end;
for i:=1 to n do
if z[i]<>0 then x[z[i]]:=1;
k:=0;
for i:=1 to m do
if x[i]<>0 then inc(ans);
writeln(ans);
close(input);
close(output);
end.