#include #include #include #include #include #include #include using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define pb push_back #define ALL(a) (a).begin(),(a).end() #define EPS (1e-10) #define EQ(a,b) (abs((a)-(b)) < EPS) #define PI 3.1415926535 typedef long long ll; typedef pair P; //typedef complex C; const int INF = 99999999; const int MAX_N = 100; const int MAX_C = 100000; int C, N; int a[MAX_N]; int dp[MAX_C + 1]; void input() { cin >> C >> N; REP(i, N) cin >> a[i]; } void solve() { REP(j, C + 1) dp[j] = INF; dp[0] = 0; REP(i, N) { REP(j, C + 1) { if (j + a[i] <= C) { dp[j + a[i]] = min(dp[j + a[i]], dp[j] + 1); } } } if (dp[C] >= INF) dp[C] = -1; cout << dp[C] << endl; } int main() { input(); solve(); }