#include #include #include #include #include #include #include #include #include #include using namespace std; typedef vector VI; typedef vector VVI; typedef vector VS; typedef pair PII; typedef long long LL; typedef unsigned long long ULL; typedef pair PIL; typedef vector VPIL; #define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++) #define sort(c) sort((c).begin(),(c).end()) #define range(i,a,b) for(int i=(a); i < (b); i++) #define rep(i,n) range(i,0,n) #define MAX_INT 2147483647 int main(){ int C, N, UB = 100001; VI a; VVI dp; cin >> C >> N; a.resize(N); rep(i,N) cin >> a[i]; dp = VVI(N+1, VI(C+1, UB)); rep(i,N){ dp[i][0] = 0; range(j,a[i],C+1) dp[i][j] = min(dp[i][j], dp[i][j-a[i]]+1); rep(j,C+1) dp[i+1][j] = dp[i][j]; } cout << ((dp[N][C] != UB)? dp[N][C] : -1) << endl; return 0; }