#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 ans = 0, sum = 0; for (int i = 0; i < n; ++i) { if (sum + w[i] <= l) { sum += w[i]; ans++; } else { break; } } cout << ans << endl; return 0; }