program cojs1682;
var
v:array[0..1010]of boolean;
a:array[1..10000010]of longint;
i,k,l,r,n,m,ans:longint;
begin
assign(input,'ha14d.in');reset(input);
assign(output,'ha14d.out');rewrite(output);
readln(n,m);
for k:=1 to m do
begin
readln(l,r);
for i:=l to r do
a[i]:=k;
end;
fillchar(v,sizeof(v),0);
for i:=1 to n do
v[a[i]]:=true;
for i:=1 to m do
if v[i] then inc(ans);
writeln(ans);
close(input);close(output);
end.