#include #include #include using namespace std; int main() { int L, N; scanf("%d%d", &L, &N); vector W(N); for (int i = 0; i < N; i++) { scanf("%d", &W[i]); } sort(W.begin(), W.end(), less()); int ans = 0; for (; ans < N; ans++) { L -= W[ans]; if (L < 0) break; } printf("%d\n", ans); return 0; }