#include #include using namespace std; int L, N, W[12345]; int main() { cin >> L; cin >> N; for (int i = 0; i < N; i++) { cin >> W[i]; } sort(W, W + N); int cnt = 0; for (int i = 0; i < N; i++) { if (L < W[i]) { break; } cnt += 1; L -= W[i]; } cout << cnt; return 0; }