#include #include #include using namespace std; int main(void) { int L,N,c = 0; vector W; scanf ("%d",&L); scanf ("%d",&N); for (int t = 0; t < N ; ++t) { int i; scanf ("%d",&i); W.push_back(i); } sort (W.begin(),W.end()); for (auto w : W) { L -= w; if (L >= 0) { c++; } else { break; } } printf("%d\n", c); return 0; }