#include using namespace std; int W[10000]; int main() { int L; cin >> L; int N; cin >> N; for (int i = 0; i < N; ++i) cin >> W[i]; sort(W, W + N); int sum = 0; for (int i = 0; i < N; ++i) { if (sum + W[i] > L) { cout << i << endl; return 0; } else { sum += W[i]; } } cout << N << endl; }