#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main(){ long long C, N; cin >> C >> N; vector a(N+1); for (int i=1; i<=N; i++) cin >> a[i]; vector> dp(N+1, vector(C+1, 1e18)); for (int i=0; i<=N; i++) dp[i][0] = 0; for (int i=1; i<=N; i++){ for (int j=1; j<=C; j++){ dp[i][j] = min(dp[i][j], dp[i-1][j]); if (j >= a[i]) dp[i][j] = min(dp[i][j], dp[i][j-a[i]] + 1); } } cout << (dp[N][C] == 1e18 ? -1 : dp[N][C]) << endl; return 0; }