var m:array[1..10001] of integer;
p,t,a,b:array[1..10001] of integer;
n,k,i,j,len:integer;
procedure pai(x:integer);
var t2,y,t1:integer;
begin
while (x*2<=len)and(a[x]>a[x*2])or((x*2+1<=LEN)and(A[X]>A[X*2+1])) do begin
if x*2=len then y:=x*2
else if a[x*2]<a[x*2+1] then y:=x*2 else y:=x*2+1;
t2:=a[y];a[y]:=a[x];a[x]:=t2;
t1:=b[y];b[y]:=b[x];b[x]:=t1;x:=y;
end;
end;
procedure delete;
begin
a[1]:=a[len];
b[1]:=b[len];
dec(len);
pai(1);
end;
begin
assign(input,'lazy.in');
reset(input);
assign(output,'lazy.out');
rewrite(output);
readln(n,k);
for i:=1 to k do begin
readln(p[i],t[i]);
a[i]:=p[i];b[i]:=t[i];
end;
len:=k;
for i:=k div 2 downto 1 do pai(i);
for i:=1 to k do begin
p[i]:=a[1];t[i]:=b[1];
delete;
end;
m[n+1]:=0;j:=k;
for i:=n downto 1 do begin
if p[j]<>i then m[i]:=m[i+1]+1 else
while p[j]=i do begin
if m[i+t[j]]>m[i] then begin
m[i]:=m[i+t[j]]
end;
j:=j-1;
end;
end;
writeln(m[1]);
close(input);
close(output);
end.