#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(int i=0; i<(n); i++) #define RREP(i, n) for(int i=(n-1); i>=0; i--) #define ALL(a) (a).begin(),(a).end() int N,C; int dp[511111]; signed main() { cin>>C>>N; vector A(N); REP(i,N) cin >> A[i]; sort(ALL(A)); REP(j,C+1) dp[j] = 1e9; dp[0] = 0; REP(i,N) REP(j,C+1) { int a = A[i]; dp[j+a] = min(dp[j+a], 1 + dp[j]); } cout << (dp[C] < 1e9 ? dp[C] : -1) << endl; return 0; }