#include using namespace std; int main() { int L, N, tmp, sum = 0; cin >> L >> N; int W[N]; for(int i = 0; i < sizeof(W)/sizeof(W[0]); i++){ cin >> W[i]; } for(int i = 0; i < N; i++){ for(int j = i + 1; j < N; j++){ if(W[i] > W[j]){ tmp = W[i]; W[i] = W[j]; W[j] = tmp; } } } int count = 0; while(L >= W[count]){ L -= W[count]; count++; } cout << count << endl; return 0; }