#include #include using namespace std; const int INF = 1 << 29; int main() { int C, N; int a[100]; cin >> C >> N; for (int j = 0; j < N; ++j) { cin >> a[j]; } int m[100001]; fill(m, m + 100001, INF); m[0] = 0; for (int j = 0; j < N; ++j) { for (int k = a[j]; k <= C; ++k) { m[k] = min(m[k], m[k - a[j]] + 1); } } if (m[C] == INF) { cout << -1 << endl; } else { cout << m[C] << endl; } return 0; }