#include int main(void){ int l,n,w[10001],swap; scanf("%d",&l); scanf("%d",&n); for(int i = 0; i < n; i++)scanf("%d",&w[i]); for(int i = 0; i < n; i++){ int min = 10001,minpoint; for(int j = i; j < n; j++){ if(min > w[j]){ min = w[j]; minpoint = j; } } swap = w[i]; w[i] = w[minpoint]; w[minpoint] = swap; } int sum = 0,count,check = 1; for(int i = 0; i < n; i++){ if(sum >= l){ break; check = 0; } sum += w[i]; count++; } if(check == 1)printf("%d\n",count); else printf("%d\n",count - 1); }