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