uses math;
var s,t,a:array[0..10001]of longint;
procedure swap(var x,y:longint);
var z:longint;
begin
z:=x;x:=y;y:=z;
end;
procedure qsort_s_up(l,r:longint);
var i,j,k:longint;
begin
i:=l;j:=r;k:=s[l+random(r-l+1)];
while i<=j do begin
while s[i]<k do i:=i+1;
while k<s[j] do j:=j-1;
if i<=j then begin
swap(s[i],s[j]);
swap(t[i],t[j]);
i:=i+1;j:=j-1;
end;
end;
if i<r then qsort_s_up(i,r);
if l<j then qsort_s_up(l,j);
end;
procedure qsort_t_up(l,r:longint);
var i,j,k:longint;
begin
i:=l;j:=r;k:=t[l+random(r-l+1)];
while i<=j do begin
while t[i]<k do i:=i+1;
while k<t[j] do j:=j-1;
if i<=j then begin
swap(a[i],a[j]);
swap(t[i],t[j]);
i:=i+1;j:=j-1;
end;
end;
if i<r then qsort_t_up(i,r);
if l<j then qsort_t_up(l,j);
end;
var maxt,n,i,x,head,ans:longint;
begin
assign(input,'
assign(output,'
readln(maxt,n);
for i:=1 to n do begin
readln(s[i],x);
t[i]:=s[i]+x-1;
a[i]:=i;
end;
qsort_s_up(1,n);
qsort_t_up(1,n);
s[0]:=0;t[0]:=0;f[0]:=0;
x:=0;
head:=1;
for i:=1 to n do
if s[i]=s[i-1]then f[i]:=f[i-1]
else begin
f[i]:=0;
while (s[i-1]<=t[head])and(t[head]<s[i])do
f[i]:=max(f[i],f[a[head]]+s[i]-t[head]-1);
end;
ans:=0;
while head<=n do ans:=max(ans,f[a[head]]+maxt-t[head]);
writeln(ans);
close(input);close(output);
end.
var s,t,a:array[0..10001]of longint;
procedure swap(var x,y:longint);
var z:longint;
begin
z:=x;x:=y;y:=z;
end;
procedure qsort_s_up(l,r:longint);
var i,j,k:longint;
begin
i:=l;j:=r;k:=s[l+random(r-l+1)];
while i<=j do begin
while s[i]<k do i:=i+1;
while k<s[j] do j:=j-1;
if i<=j then begin
swap(s[i],s[j]);
swap(t[i],t[j]);
i:=i+1;j:=j-1;
end;
end;
if i<r then qsort_s_up(i,r);
if l<j then qsort_s_up(l,j);
end;
procedure qsort_t_up(l,r:longint);
var i,j,k:longint;
begin
i:=l;j:=r;k:=t[l+random(r-l+1)];
while i<=j do begin
while t[i]<k do i:=i+1;
while k<t[j] do j:=j-1;
if i<=j then begin
swap(a[i],a[j]);
swap(t[i],t[j]);
i:=i+1;j:=j-1;
end;
end;
if i<r then qsort_t_up(i,r);
if l<j then qsort_t_up(l,j);
end;
var maxt,n,i,x,head,ans:longint;
begin
assign(input,'
assign(output,'
readln(maxt,n);
for i:=1 to n do begin
readln(s[i],x);
t[i]:=s[i]+x-1;
a[i]:=i;
end;
qsort_s_up(1,n);
qsort_t_up(1,n);
s[0]:=0;t[0]:=0;f[0]:=0;
x:=0;
head:=1;
for i:=1 to n do
if s[i]=s[i-1]then f[i]:=f[i-1]
else begin
f[i]:=0;
while (s[i-1]<=t[head])and(t[head]<s[i])do
f[i]:=max(f[i],f[a[head]]+s[i]-t[head]-1);
end;
ans:=0;
while head<=n do ans:=max(ans,f[a[head]]+maxt-t[head]);
writeln(ans);
close(input);close(output);
end.