#include typedef long long ll; using namespace std; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1e9; const int MOD = 1e9+7; const ll LINF = 1e18; #define REP(i,n) for(int i=0;i<(n);++i) #define COUT(x) cout<<(x)<<"\n" #define COUT16(x) cout << fixed << setprecision(16) << (x) << "\n"; int main(){ int l,n; cin >> l >> n; vectorw(n); REP(i,n)cin >> w[i]; sort(w.begin(),w.end()); vector wa(n+1,0); REP(i,n){ wa[i+1] = wa[i] + w[i]; } int ans; for(int i=0;i<=n;i++){ if(wa[i]<=l){ ans = i; } } COUT(ans); }