#include int main() { int L, N; std::vector W; scanf("%d\n", &L); scanf("%d\n", &N); for (int i = 0; i < N; i++) { int temp; scanf("%d", &temp); W.push_back(temp); } std::sort(W.begin(), W.end()); int count, total = 0; for (count = 0; count < W.size(); count++) { total += W.at(count); if (total > L) break; } printf("%d\n", count); return 0; }