#include using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); const int INF = 1000000; int c, n, a[100]; cin >> c >> n; vector< vector > dp(n + 1, vector(c + 1, INF)); for(int i = 0; i < n; i++){ cin >> a[i]; dp[i][0] = 0; } dp[n][0] = 0; for(int i = 1; i <= n; i++) { for(int j = 1; j < a[i - 1]; j++) { dp[i][j] = dp[i - 1][j]; } for(int j = a[i - 1]; j <= c; j++) { dp[i][j] = min(dp[i - 1][j], dp[i][j - a[i - 1]] + 1); } } if (dp[n][c] == INF) cout << -1 << "\n"; else cout << dp[n][c] << "\n"; return 0; }