#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, size = 0; rep(i, N) { size += w[i]; count++; if (L<=size) { cout << count; return 0; } } return 0; }