var
n,m,i,j:longint;
a,b,f:array[0..20000]of longint;
g:array[0..20000]of boolean;
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;
procedure init;
var
i:longint;
begin
assign(input,'lazy.in'); reset(input);
assign(output,'lazy.out'); rewrite(output);
readln(m,n);
for i:=1 to n do
readln(a[i],b[i]);
end;
begin
init;
sort(1,n);
i:=n; j:=m;
repeat
if j<>a[i] then f[j]:=f[j+1]+1
else repeat
if f[j+b[i]]>f[j] then f[j]:=f[j+b[i]];
dec(i);
until a[i]<>a[i+1];
dec(j);
until j<1;
writeln(f[1]);
close(input);
close(output);
end.