#include using namespace std; typedef long long ll; #define debug(x) cerr << x << '\n' #define all(x) (x).begin(), (x).end() #define exist(s, e) ((s).fine(e) != (s).end()) int main() { cin.tie(0); ios::sync_with_stdio(false); ll l, n; cin >> l >> n; vector w(n); for (ll i = 0;i < n;i++) { cin >> w[i]; } sort(all(w)); ll i = 0; for (ll tmp = 0;tmp <= l && i < n;tmp += w[i++]) ; cout << i-1; return 0; }