/* -*- coding: utf-8 -*- * * 247.cc: No.247 線形計画問題もどき - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_C = 100000; const int MAX_N = 100; const int INF = 1 << 30; /* typedef */ /* global variables */ int as[MAX_N]; int dp[MAX_C + 1]; /* subroutines */ /* main */ int main() { int c, n; cin >> c >> n; for (int i = 0; i < n; i++) cin >> as[i]; dp[0] = 0; for (int i = 1; i <= c; i++) { int mind = INF; for (int j = 0; j < n; j++) if (i >= as[j]) { int d = dp[i - as[j]] + 1; if (mind > d) mind = d; } dp[i] = mind; } printf("%d\n", (dp[c] >= INF) ? -1 : dp[c]); return 0; }