#include // cout, endl, cin #include //sqrt pow #include // string, to_string, stoi #include // vector #include // min, max, swap, sort, reverse, lower_bound, upper_bound #include // pair, make_pair #include // tuple, make_tuple #include // int64_t, int*_t #include // printf #include // map #include // queue, priority_queue #include // set #include // stack #include // dequef #include // unordered_map #include // unordered_set #include // bitset #include // isupper, islower, isdigit, toupper, tolower #include #define rep(i, n) for (int i = 0; i < n; i++) using ll = long long; using ld = long double; #define vi vector #define vvi vector #define vl vector #define pii pair #define pll pair #define all(a) (a).begin(), (a).end() #define mod 1000000007 using namespace std; int main(){ int l,n; cin >> l >> n; vi w(n); rep(i, n) cin >> w[i]; sort(all(w)); ll tot = 0; rep(i, n){ tot += w[i]; if(tot > l){ cout << i << endl; return 0; } } }