#include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) typedef long long ll; typedef unsigned long long ull; int N, C; int A[101]; int constexpr INF = 1e6; int constexpr MAX = 1e7+1; int dp[MAX]; int main() { cin >> C >> N; rep(i, N) cin >> A[i]; rep(i, C+1) dp[i] = INF; dp[0] = 0; rep(i, N) rep(j, C+1) if(j - A[i] >= 0 && dp[j - A[i]] < INF) dp[j] = min(dp[j], dp[j - A[i]] + 1); cout << (dp[C] == INF ? -1 : dp[C]) << endl; return 0; }