#include #include #include using namespace std; int main() { int l, n; cin >> l >> n; vector w(n); for (int i = 0; i < n; ++i) { cin >> w[i]; } sort(w.begin(), w.end()); int sum = 0; int i; for (i = 0; i < n; ++i) { if (sum + w[i] > l) { break; } sum += w[i]; } cout << i << endl; return 0; }