#include #include template std::vector vec(int len, T elem) { return std::vector(len, elem); } void solve() { int t, n; std::cin >> t >> n; std::vector xs(n); for (auto& x : xs) std::cin >> x; auto dp = vec(n + 1, vec(1 << n, t + 1)); dp[0][0] = 0; for (int k = 0; k < n; ++k) { for (int b = 0; b < (1 << n); ++b) { if (dp[k][b] > t) continue; // reset dp[k + 1][b] = 0; // solve for (int i = 0; i < n; ++i) { if ((b >> i) & 1) continue; int nb = b | (1 << i); dp[k][nb] = std::min(dp[k][nb], dp[k][b] + xs[i]); } } } for (int k = 0; k <= n; ++k) { if (dp[k].back() == 0) { std::cout << k << "\n"; return; } } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }