#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; int dp[105][100005]; int main(){ int C, N, aa; vector a; cin >> C; cin >> N; rep(i,N){ cin >> aa; a.push_back(aa); } rep(i,105){ rep(j,100005){ dp[i][j] = 100000000; } } int cnt = 1; int now = a[0]; while(now < 100005){ dp[0][now] = cnt; now += a[0]; cnt++; } rep(i,N-1){ rep(j,100005){ dp[i+1][j] = min(dp[i+1][j], dp[i][j]); if(j>=a[i+1]){ dp[i+1][j] = min(dp[i+1][j], dp[i+1][j-a[i+1]]+1); } } } if(dp[N-1][C]==100000000){ cout << -1 << endl; }else{ cout << dp[N-1][C] << endl; } return 0; }