#include #include using namespace std; int L; int N; int W[10000]; void input(istream& in) { in >> L; in >> N; for (int i = 0; i < N; i++) in >> W[i]; } int resolve() { sort(W, W + N); int sum = 0; for (int i = 0; i < N; i++) { sum += W[i]; if (sum > L) { return i; } } return N; } int main(int argc, char **argv) { input(cin); cout << resolve() << endl; return 0; }