#include<cstdio>
#include<cstring>
#include<algorithm>
using std::min;
const int M=557,inf=0x3f3f3f3f;
int read(){
int ans=0,f=1,c=getchar();
while(c<‘0‘||c>‘9‘){if(c==‘-‘) f=-1; c=getchar();}
while(c>=‘0‘&&c<=‘9‘){ans=ans*10+(c-‘0‘); c=getchar();}
return ans*f;
}
int ans=inf,n,m,f[M][M];
int k,s1[M],s2[M];
int main(){
memset(f,0x3f,sizeof(f));
n=read(); m=read();
for(int i=1;i<=m;i++){
k=read(); s1[i]=s1[i-1]+k;
k=read(); s2[i]=s2[i-1]+k;
}
f[0][0]=0;f[1][1]=1;f[1][0]=2;
for(int k=2;k<=m;k++){
for(int i=1;i<=k;i++)if(s1[k]-s1[k-i]<=n)
for(int j=0;j<=k-i;j++)if((s1[k]-s1[k-i])+(s2[k-i]-s2[k-i-j])<=n)
f[k][i]=std::min(f[k][i],f[k-i][j]+1);
for(int i=1;i<=m;i++)if(s2[k]-s2[k-i]<=n)f[k][0]=min(f[k][0],f[k][i]+1);
}
ans=f[m][0]+1;
for(int i=1;i<=m;i++) if(s2[m]-s2[m-i]<=n) ans=min(ans,f[m][i]+2);
printf("%d\n",ans);
return 0;
}