#include using namespace std; template using vec = vector; template using vvec = vector>; constexpr int64_t mpow(int64_t a, int64_t b, int64_t mod = 1000000007) { if (b <= 0) { return 1; } if (b == 1) { return a % mod; } if (b == 2) { return (a * a) % mod; } return (max(a * (b & 1), (int64_t)1) * mpow(mpow(a, b / 2, mod), 2, mod)) % mod; } constexpr int64_t mdiv(int64_t a, int64_t b, int64_t mod = 1000000007) { return (a * mpow(b, mod - 2, mod)) % mod; } int main() { int l, n; cin >> l >> n; vec w(n); for (auto &e : w) cin >> e; sort(w.begin(), w.end()); int ans = 0; for (int i = 0; i < n; ++i) { if (l - w[i] < 0) break; l -= w[i]; ++ans; } cout << ans << endl; }