#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int INF = 1001001001; // constexpr int mod = 1000000007; constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int C, N; cin >> C >> N; vector a(N); for(int i = 0; i < N; ++i) cin >> a[i]; vector> dp(N + 1, vector(C + 1, INF)); dp[0][0] = 0; int counter = 0; for(int i = 0; i < N; ++i){ for(int m = 0; m < a[i]; ++m){ int minv = INF; for(int s = m; s <= C; s += a[i]){ minv += 1; chmin(minv, dp[i][s]); chmin(dp[i + 1][s], minv); } } } int ans = dp[N][C]; if(ans == INF) ans = -1; cout << ans << endl; return 0; }