#include using namespace std; int dp[1 << 18]; const int M = 1000000007; int main() { // O(2^{2N}) int T, n; cin >> T >> n; vector t(n); for (int i = 0; i < n; ++i) cin >> t[i]; vector pl; for (int i = 1; i < (1 << n); ++i) { int s = 0, mi = M; dp[i] = n; for (int j = 0; j < n; ++j) { if ((i >> j) & 1) s += t[j]; else mi = min(mi, t[j]); } if (s <= T) { if (s + mi > T) pl.push_back(i); dp[i] = 1; continue; } } for (int i = 0; i < (1 << n); ++i) { if (dp[i] < 2) continue; for (int j : pl) dp[i] = min(dp[i], dp[i & ~j] + 1); } cout << dp[(1 << n) - 1] << "\n"; return 0; }