#include using namespace std; using ll = long long; using VI = vector; using P = pair; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++) #define ALL(a) (a).begin(),(a).end() constexpr int INF = 1001001001; constexpr ll LINF = 1001001001001001001ll; constexpr int DX[] = {1, 0, -1, 0}; constexpr int DY[] = {0, 1, 0, -1}; template< typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true); } template< typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true); } const ll MOD = 1000000007; int main() { int N, K; cin >> N >> K; VI A(N); REP(i, N) cin >> A[i]; vector> L(N + 1, vector(K + 1, false)); vector> R(N + 1, vector(K + 1, false)); L[0][0] = true; R[N][0] = true; REP(i, N) { REP(j, K + 1) { L[i + 1][j] = L[i + 1][j] | L[i][j]; if (j + A[i] <= K) L[i + 1][j + A[i]] = L[i + 1][j + A[i]] | L[i][j]; R[N - i - 1][j] = R[N - i - 1][j] | R[N - i][j]; if (j + A[N - 1 - i] <= K) R[N - i - 1][j + A[N - 1 - i]] = R[N - i - 1][j + A[N - 1 - i]] | R[N - i][j]; } } if (!L[N][K]) { cout << -1 << endl; return 0; } int ans = 0; REP(i, N) { bool f = true, g = false; REP(j, K + 1) { if (L[i][j]) { if (R[i + 1][K - j]) f = false; if (j + A[i] <= K && R[i + 1][K - j - A[i]]) g = true; } } if (f && g) { // cout << i << endl; ans++; } } cout << ans << endl; /* REP(i, N + 1) { REP(j, K + 1) cout << L[i][j]; cout << endl; REP(j, K + 1) cout << R[i][j]; cout << endl << endl; } */ }