#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 c; int n; int a[100]; cin >>c >> n; fill(a,a+100,-1);//invalid error on sort rep(i,n) { cin >> a[i]; } map dp[10001]; dp[0].insert(make_pair(0,0)); sort(a,a+100,greater()); rep(i,n) { for (auto ittr = dp[i].begin(); ittr != dp[i].end() ; ittr++) { for (int k = 0;; k++) { int x = ittr->first; int y = ittr->second; if ((x + k*a[i]) > c) { break; } auto next = dp[i+1].find(x + k*a[i]); if (next == dp[i+1].end()) { dp[i+1].insert(make_pair(x +k*a[i],y+k)); continue; } if ( next->second > y+k) { dp[i+1].erase(next->first); dp[i+1].insert(make_pair(x+k*a[i],y+k)); } } } } if (dp[n].find(c) != dp[n].end()) { int ans = dp[n].find(c)->second; cout << ans <