#include #include #include #include using namespace std; int main() { int L,N; cin >> L; cin >> N; vector W(N); for (int i = 0; i < N; i++) cin >> W[i]; sort(W.begin(),W.end()); int ret = 0; while (L>0) L -= W[ret++]; if (L<0) ret--; cout << ret << endl; return 0; }