#include int main(void) { int i, j, L, N, W[10000]; int min, imin, length = 0, num = 0; scanf("%d", &L); scanf("%d", &N); for(i = 0;i < N;i++){ scanf("%d", &W[i]); } for(j = 0;j < N;j++){ min = 10000; for(i = 0;i < N;i++){ if(W[i] < min && W[i] != 0){ min = W[i]; imin = i; } } if(length + W[imin] <= L){ length += W[imin]; num++; } W[imin] = 0; } printf("%d\n", num); return 0; }