#include #include #define N_MAX 10000 using namespace std; int main() { int L, N, W[N_MAX], ans = 0; cin >> L >> N; for (int i = 0; i < N; ++i) cin >> W[i]; sort(W, W + N); for (int i = 0; i < N && W[i] <= L; ++i, ++ans) L -= W[i]; cout << ans << endl; return 0; }