#include using namespace std; int dp[1 << 18][20]; const int M = 1000000007; int main() { // O(N^2 2^N) int T, n; cin >> T >> n; vector t(n); for (int i = 0; i < n; ++i) cin >> t[i]; for (int i = 1; i < (1 << n); ++i) for (int j = 0; j <= n; ++j) dp[i][j] = M; for (int i = 1; i < (1 << n); ++i) { for (int j = 0; j < n; ++j) { if ((i >> j) & 1) { for (int k = 0; k < n; ++k) { dp[i][k] = min(dp[i][k], dp[i ^ (1 << j)][k] + t[j]); if (dp[i][k] <= T) dp[i][k + 1] = 0; } } } } for (int i = 0; i <= n; ++i) { if (!dp[(1 << n) - 1][i]) { cout << i << "\n"; return 0; } } }