#include #include #include using namespace std; #define RREP(i,s,e) for (i = s; i >= e; i--) #define rrep(i,n) RREP(i,n,0) #define REP(i,s,e) for (i = s; i < e; i++) #define rep(i,n) REP(i,0,n) #define INF 100000000 typedef long long ll; int a[100001]; int dp[100001]; int main() { int i, j, c, n; cin >> c >> n; fill(dp+1,dp+c+1,INF); rep (i,n) { int a; cin >> a; REP (j,a,c+1) dp[j] = min(dp[j-a]+1,dp[j]); } if (dp[c] != INF) cout << dp[c] << endl; else cout << -1 << endl; return 0; }