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