#include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) typedef long long ll; typedef unsigned long long ull; int N, C; int A[101]; int constexpr MOD = 1e9+7; int constexpr invalid = std::numeric_limits::max() / 6; std::unordered_map memo; std::hash ullhash; ll solve(int csum, int i, int xsum) { ull hash = ullhash(csum) ^ ullhash(xsum) ^ ullhash(i); if(memo.find(hash) != memo.end()) { return memo[hash]; } if(i == -1) { if(csum == 0) { return xsum; } else { return invalid; } } if(csum < 0) { return invalid; } ll& ret = memo[hash]; ret = invalid; for(int x = csum / A[i] + 1; x >= 0; x--) { ret = min(ret, solve(csum - A[i] * x, i-1, xsum + x)); } return ret; } int main() { cin >> C >> N; rep(i, N) cin >> A[i]; sort(A, A+N); std::reverse(A, A+N); auto ret = solve(C, N-1, 0); if(ret == invalid) { cout << -1 << endl; } else { cout << ret << endl; } return 0; }