#include <stdio.h>
#include <stdlib.h>

int c[21][50001];
int i[21];

int minv(int a, int b){


 if(a > b)
  return b;

 else
  return a;


}

int main(){
int m, n, count, count2 = 0;


 for(m = 0; m < 21; m++){
  c[m][0] = 0;
 }
 for(m = 1; m < 50001; m++){
   c[1][m] = m;
 }


  scanf("%d", &m);
  scanf("%d", &n);


 for(count = 1; count <= n; count++){
  scanf("%d", &i[count]);

 }

 for(count = 2; count <= n; count++){
  for(count2 = 0; count2  <= m; count2++){
     if(count2 - i[count] >= 0)
       c[count][count2] = minv(c[count][count2 - i[count]] + 1, c[count-1][count2]);
      else
       c[count][count2] = c[count-1][count2];
  }
 }

 printf("%d\n", c[n][m]);

 return 0;
}