#include using namespace std; int main() { int W; int N; cin >> W >> N; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A.begin(), A.end()); int now = 0; for (int i = 0; i < N; i++) { if (now + A[i] > W) { cout << i; return 0; } now += A[i]; } }