#include using namespace std; #ifdef _RUTHEN #include "debug.hpp" #else #define show(...) true #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) template using V = vector; int main() { ios::sync_with_stdio(false); cin.tie(0); ll N, K; cin >> N >> K; V A(N); rep(i, N) cin >> A[i]; V> dp1(N + 1, V(K + 1, 0)), dp2(N + 1, V(K + 1, -1)); dp1[0][0] = 1; rep(i, N) { for (int k = 0; k <= K; k++) { if (dp1[i][k] == 0) continue; dp1[i + 1][k] = 1; dp2[i + 1][k] = k; if (k + A[i] <= K) { dp1[i + 1][k + A[i]] = 1; dp2[i + 1][k + A[i]] = k; } } } show(dp1, dp2); if (dp1[N][K] == 0) { cout << -1 << '\n'; return 0; } set S; int k0 = K; for (int i = N; i > 0; i--) { if (dp2[i][k0] != k0) { // add S.insert(i - 1); k0 = dp2[i][k0]; } } V> dp3(N + 1, V(K + 1, 0)); dp3[0][0] = 1; rep(i, N) { for (int k = 0; k <= K; k++) { if (dp3[i][k] == 0) continue; dp3[i + 1][k] = 1; if (k + A[i] <= K && S.count(i) == 0) { dp3[i + 1][k + A[i]] = 1; } } } int ans = 0; for (auto &s : S) { if (dp3[N][A[s]] == 0) { ans++; } } show(S); cout << ans << '\n'; return 0; }