#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int main(void){ int l,n,ans = 0; cin >> l >> n; vector w(n); rep(i,n) cin >> w[i]; sort(w.begin(),w.end()); rep(i,n){ if(l >= w[i]){ ans++; l -= w[i]; } } cout << ans << endl; return 0; }