#include using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); const int INF = 1000000; int c, n; cin >> c >> n; vector a(n); vector dp(c + 1, INF); for(int i = 0; i < n; i++){ cin >> a[i]; } dp[0] = 0; for(int i = 0; i < n; i++) { for(int j = a[i - 1]; j <= c; j++) { dp[j] = min(dp[j], dp[j - a[i - 1]] + 1); } } if (dp[c] == INF) cout << -1 << "\n"; else cout << dp[c] << "\n"; return 0; }