#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 template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } //constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; const long double PI = acos((long double)(-1)); using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; int dp[2][100001]; void init(int x) { for (int i = 0; i <= 100000; i++) dp[x][i] = inf; } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ int C; scanf("%d", &C); int n; scanf("%d", &n); vector a(n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); init(0), init(1); int cur = 0; int nxt = 1; dp[0][0] = 0; for (int i = 0; i < n; i++) { init(nxt); for (int j = 0; j <= C; j++) { if (dp[cur][j] == -inf) continue; for (int k = 0; k <= C; k++) { if (a[i] * k + j > C) break; chmin(dp[nxt][a[i] * k + j], dp[cur][j] + k); } } swap(cur, nxt); } int res = dp[cur][C]; if (res == inf) res = -1; cout << res << endl; return 0; }