program lazy;
var
m:array [0..10000] of record
x,y:integer;
end;
f:array [0..10000] of integer;
p,n,k,i,j:integer;
procedure quicksort(a,b:integer);
var st,ste,l,r:integer;
begin
if a<b then begin
l:=a;r:=b;
st:=m[a].x;ste:=m[a].y;
repeat
while (l<r) and (m[r].x<=st) do dec(r);
if l<r then begin
m[l].x:=m[r].x;
m[l].y:=m[r].y;
inc(l);
end;
while (l<r) and (m[l].x>=st) do inc(l);
if l<r then begin
m[r].x:=m[l].x;
m[r].y:=m[l].y;
dec(r);
end;
until l=r;
m[l].x:=st;
m[l].y:=ste;
quicksort (a,l-1);
quicksort (l+1,b);
end;
end;
begin
assign (input,'lazy.in');
reset (input);
readln (n,k);
for i:=1 to k do with m[i] do readln (x,y);
quicksort(1,k);p:=1;
close (input);
assign (output,'lazy.out');
rewrite (output);
fillchar (f,sizeof(f),0);
for i:=n downto 1 do
if m[p].x=i then begin
f[i]:=f[m[p].x+m[p].y];
inc(p);
while m[p].x=i do begin
if f[i]<f[m[p].x+m[p].y] then f[i]:=f[m[p].x+m[p].y];
inc(p);
end;
end
else f[i]:=f[i+1]+1;
writeln(f[1]);
close (output);
end.