#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 changing(int s, int n){


 if(s == 1)
  return c[s][n];


 c[s-1][n] = changing(s-1, n);

 if(n-i[s] >= 0){
  c[s][n-i[s]] = changing(s, n-i[s]);
 return minv(c[s-1][n], c[s][n-i[s]]+1);
 }

 else
 return c[s-1][n];

}

int main(){
int m, n, count;


 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]);

 }


  printf("%d\n", changing(n, m));


 return 0;
}