#include #include using namespace std; int L, N; int W[10000]; int main() { cin >> L >> N; for (int i = 0; i < N; i++) { cin >> W[i]; } sort(W, W + N); int sum = 0; for (int i = 0; i < N; i++) { sum += W[i]; if (sum > L) { cout << i << endl; return 0; } } cout << N << endl; return 0; }