校门外的树
type
treedata=record
s,t,l,r:longint;
bj:boolean;
end;
var
tree:array[1..200001]of treedata;
l,m,i,j,k,tot,x,y,ans:longint;
procedure DLR(i:longint);
begin
if tree[i].bj then
begin inc(ans,tree[i].t-tree[i].s+1); exit end;
if tree[i].l<>0 then DLR(tree[i].l);
if tree[i].r<>0 then DLR(tree[i].r);
end;
procedure Insert(i:longint);
begin
if (tree[i].s>=x) and (tree[i].t<=y) then
tree[i].bj:=true else
begin
if (x<=(tree[i].s+tree[i].t)div 2)and(tree[i].l<>0)
then Insert(tree[i].l);
if (y>=(tree[i].s+tree[i].t)div 2)and(tree[i].r<>0)
then Insert(tree[i].r);
end;
end;
procedure MakeTree(a,b:longint);
var k,m:longint;
begin
m:=tot;
k:=(a+b)div 2;
tree[tot].s:=a;
tree[tot].t:=b;
tree[tot].bj:=false;
if b-a>=1 then
begin
inc(tot); tree[m].l:=tot; maketree(a,k);
inc(tot); tree[m].r:=tot; maketree(k+1,b);
end;
end;
begin
assign(input,'tree.in');
reset(input);
assign(output,'tree.out');
rewrite(output);
readln(l,m);
tot:=1;
Maketree(0,l);
for i:=1 to m do
begin
readln(x,y);
Insert(1);
end;
ans:=0;
DLR(1);
writeln(l+1-ans);
close(input);
close(output);
end.