#include<stdio.h>
int main(void)
{
  int n,m,i,j;
  scanf("%d%d",&n,&m);
  int c[m],LP[n+1][m];
  for(i=0;i<m;i++) scanf("%d",&c[i]);
  for(i=0;i<=n;i++){
    LP[i][0]=i;
  }
  for(j=1;j<m;j++){
    for(i=0;i<=n;i++){
      int x=10000,y=10000,z=10000,min;
      x=LP[i][j-1];
      if(i-c[j]>=0) y=LP[i-c[j]][j-1]+1;
      if(i-c[j]>=0) z=LP[i-c[j]][j]+1;
      //if(i==4&&j==1) printf("x:%d y:%d z:%d\n",x,y,z);
      min=x;
      if(z<min) min=z;
      if(y<min) min=y;
      LP[i][j]=min;
    }
  }
/*  for(j=0;j<m;j++){
    for(i=0;i<=n;i++) {printf("%d ",LP[i][j]);}
    printf("\n");
  }
  */
  printf("%d\n",LP[n][m-1]);
  return 0;
}

