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