#include int main(void){ int l,n,w[10001],swap,sum = 0,check = 0; 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; } for(int i = 0; i < n; i++){ sum += w[i]; if(sum > l){ check = 1; printf("%d\n",i); break; } } if(check == 0)printf("%d\n",n); }