#include int main(void){ int i, j, tmp, L, N; int W[10000] = {}; scanf("%d%d", &L, &N); for( i = 0; i < N; i++){ scanf("%d",&W[i]); } for( i = 0; i < N - 1; ++i){ for ( j = i + 1; j < N; ++j){ if ( W[i] > W[j]){ tmp = W[i]; W[i] = W[j]; W[j] = tmp; } } } int goukei = 0, count = 0; for ( i = 0; goukei < L; i++){ goukei += W[i]; count++; } if(goukei > L){ count--; } printf ("%d",count); return 0; }