#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][100001]; int c; int n; int a[100]; cin >> c >> n; fill(a,a+100,-1);//invalid error on sort rep(i,100) { rep(j,100000) { dp[i][j] = 1000000; } } rep(i,n) { cin >> a[i]; } sort(a,a+100,greater()); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < c+1; j++) { if (j < a[i]) { dp[i+1][j]= dp[i][j]; } else { dp[i+1][j] = min(dp[i][j], dp[i+1][max(0,j-a[i])] + 1 ); } } } if (dp[n][c] != MOD) { cout << dp[n][c] << endl; return 0; } cout << "-1" << endl; return 0; }