#define _USE_MATH_DEFINES #include #include #include #include #include //#include #include #include #include #include #include #include ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define P(p) cout<<(p)< ///////// typedef long long LL; typedef long double LD; ///////// using namespace::std; ///////// int main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;// //cout << setprecision(10);// int C,N; cin>>C>>N; int A[100]; rep(i,N){cin>>A[i];} sort( A,A+N, greater() ); const int dpmax = 100001; int dp[dpmax]; rep(i,dpmax){ dp[i] = 1<<28; } dp[0]=0; rep(i,dpmax){ rep(j,N){ if(i+A[j] < dpmax){ dp[ i + A[j] ] = min( dp[i+A[j]] , dp[i]+1 ); } } } if(dp[C] == 1<<28){ P(-1); }else{ P(dp[C]); } return 0; }