#include using namespace std; typedef unsigned long long ul; typedef signed long long ll; ul over = 1000000007; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cout << fixed; ll l, n; cin >> l >> n; ll w[n]; for (ll i = 0; i < n; ++i) cin >> w[i]; sort(w, w+n); ll ans = 0; for (ll i = 0, block = 0; block + w[i] <= l; ++i) { ans++; block+=w[i]; } cout << ans << endl; return 0; }