#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(x, to) for (int x = 0; x < (to); x++) #define REP(x, a, to) for (int x = (a); x < (to); x++) #define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++) #define EPS (1e-14) #define INF (1e+9) using namespace std; typedef long long ll; typedef pair PII; typedef pair PLL; typedef complex Complex; typedef vector< vector > Mat; int C; int N; int a[100005]; int dp[105][100005]; int main() { rep(i, 105) rep(j, 100005) dp[i][j] = INF; cin >> C; cin >> N; rep(i, N) cin >> a[i]; dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= C; j++) { dp[i + 1][j] = dp[i][j]; if (j - a[i] >= 0) { dp[i + 1][j] = min(dp[i + 1][j], dp[i + 1][j - a[i]] + 1); } } } if (dp[N][C] == INF) { cout << -1 << endl; } else { cout << dp[N][C] << endl; } return 0; }