#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define OB (bitset<32>) #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define ALLOF(c) begin(), (c),end() typedef long long ll; #define PI acos(-1) #define EPS 0.000000001 #define MOD 1000000007 int main() { int dp[101][10001]; int c; int n; int a[100]; cin >>c >> n; fill(a,a+100,-1);//invalid error on sort rep(i,101) { rep(j,100001) { dp[i][j] = 10000000; } } rep(i,n) { cin >> a[i]; } sort(a,a+100,greater()); dp[0][0] = 0; rep(i,n+1) { rep(j,c+1) { if (j < a[i]) { dp[i+1][j]= dp[i][j]; } else { dp[i+1][j] = min(dp[i][j],dp[i+1][j-a[i]]+1); } } } if (dp[n][c]!= MOD) { cout << dp[n][c] << endl; return 0; } cout << "-1" << endl; return 0; }