#include<iostream> #include <vector> #include <climits> using namespace std; int main() { int m, n; while (cin >> m >> n) { vector<int> dp(m + 1, INT_MAX); dp[0] = 0; for (int i = 0; i < n; i++) { int value; cin >> value; for (int j = m; j >= value; j--) { if (dp[j - value] != INT_MAX && dp[j - value] + 1 < dp[j]) { dp[j] = dp[j - value] + 1; } } } cout << (dp[m] == INT_MAX ? 0 : dp[m]) << endl; } return 0; }