#include using namespace std; #define rep(i, f, n) for (int i = (f); i < (n); i++) #define rrep(i, f, n) for (int i = int(n) - 1; i >= f; i--) typedef long long ll; typedef pair P; template auto Sum(T a, U b) -> decltype(a + b) { return a + b; } template inline bool amax(T &a, U b) { if (b > a) { a = b; return true; } return false; } template inline bool amin(T &a, U b) { if (b < a) { a = b; return true; } return false; } int main() { int N, K; cin >> N >> K; vector A(N + 1); rep(i, 1, N + 1) cin >> A[i]; bool dpl[N + 2][K + 1], dpr[N + 2][K + 1]; rep(i, 0, N + 2) rep(j, 0, K + 2) { dpl[i][j] = false; dpr[i][j] = false; } dpl[0][0] = true; dpr[N + 1][0] = true; rep(i, 1, N + 1) rep(j, 0, K + 1) { dpl[i][j] = dpl[i - 1][j]; if (j >= A[i]) dpl[i][j] |= dpl[i - 1][j - A[i]]; } rrep(i, 1, N + 1) rep(j, 0, K + 1) { dpr[i][j] = dpr[i + 1][j]; if (j >= A[i]) dpr[i][j] |= dpr[i + 1][j - A[i]]; } if (!dpl[N][K]) { cout << -1 << endl; return 0; } int ans = 0; rep(i, 1, N + 1) { bool ok = true; rep(j, 0, K + 1) { if (dpl[i - 1][j] && dpr[i + 1][K - j]) ok = false; } if (ok) ans++; } cout << ans << endl; }