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