#include #include #include using namespace std; const int INF = 1e7; int main() { int c, n; cin >> c >> n; vector a(n, 0); for (int i = 0; i < n; i++) { cin >> a[i]; } vector dp(1e5 * 2 + 1, INF); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < c; j++) { if (dp[j] != INF) { dp[j + a[i]] = min(dp[j + a[i]], dp[j] + 1); } } } if (dp[c] == INF) { cout << -1 << endl; } else { cout << dp[c] << endl; } return 0; }