#include #include using namespace std; class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x a; vector> dp; int nya(int i, int j) { if(dp[i][j] != -1) { return dp[i][j]; } if(i == n) { return dp[i][j] = c==j ? 0 : inf; } int res = inf, p = j; for(int x=0; p<=c; x++, p+=a[i]) { res = min(res, nya(i+1, p) + x); } return dp[i][j] = res; } int main(void) { scanf("%d%d", &c, &n); a.assign(n, 0); for(int i : range(n)) { scanf("%d", &a[i]); } dp.assign(n+10, vector(c+10, -1)); int res = nya(0, 0); if(res == inf) { res = -1; } printf("%d\n", res); return 0; }