#include #include #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) #define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i)) template bool setmin(T & l, T const & r) { if (not (r < l)) return false; l = r; return true; } using namespace std; const int inf = 1e9+7; int main() { int c, n; cin >> c >> n; vector as(n); repeat (i,n) cin >> as[i]; vector dp(c+1, inf); dp[0] = 0; repeat_from (i,1,c+1) { for (int a : as) { if (0 <= i-a) { setmin(dp[i], dp[i-a] + 1); } } } cout << (dp[c] == inf ? -1 : dp[c]) << endl; return 0; }