#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) { if (count == 1) { count++; } cout << count-1; return 0; } } return 0; }