program lazy;
var i,j,k,n,p:longint;
a,b:array[1..10000] of longint;
f:array[1..10001] of longint;
procedure sort(l,r:longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]>x do inc(i);
while x>a[j] do dec(j);
if not(i>j)
then begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
y:=b[i];
b[i]:=b[j];
b[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
assign(input,'lazy.in');
assign(output,'lazy.out');
reset(input);
rewrite(output);
read(n,k);
for i:=1 to k do
read(a[i],b[i]);
sort(1,k);
p:=1;
fillchar(f,sizeof(f),0);
for i:=n downto 1 do
if a[p]=i
then begin
f[i]:=f[a[p]+b[p]];
inc(p);
while a[p]=i do
begin
if f[i]<f[a[p]+b[p]]
then f[i]:=f[a[p]+b[p]];
inc(p);
end;
end
else f[i]:=f[i+1]+1;
writeln(f[1]);
close(input);
close(output);
end.