#include #include #include int main(void) { using namespace std; int l, n; vector W; scanf("%d%d", &l, &n); for (int i = 0; i < n; i++) { int tmp; scanf("%d", &tmp); W.push_back(tmp); } sort(W.begin(), W.end()); int sum = 0; int i = 0; while (sum < l) { sum += W[i]; i++; } printf("%d\n", i - 1); }