#include #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using pii = pair; int main() { int l, n; cin >> l >> n; vector w(n); rep(i, n) cin >> w[i]; sort(w.begin(), w.end()); int ans = 0; rep(i, n) { if (l >= w[i]) ans++, l -= w[i]; else break; } cout << ans << endl; return 0; }