#include using namespace std; int main() { int L, N, W[1000]; int max = 0; cin >> L >> N; for (int i = 0; i < N; i++) { cin >> W[i]; } for (int i = 0; i < N - 1; i++) { int j = i; for (int k = i; k < N; k++) { if (W[k] < W[j]) { j = k; } } if (i < j) { double swap = W[i]; W[i] = W[j]; W[j] = swap; } } for (int i = 0; i < N; i++) { max += W[i]; if (max > L) { cout << i << endl; break; } } return 0; }