#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } constexpr int MAX_K = 100'010; using BS = bitset; int N, K; vector A; int ansAny; vector ans; void solve(int l, int r, const BS &bs) { if (bs[K]) { ansAny = 1; return; } if (l + 1 == r) { if (!bs[K] && bs[K - A[l]]) { ansAny = 1; ans[l] = 1; } } else { const int mid = (l + r) / 2; { BS bbs = bs; for (int i = mid; i < r; ++i) { bbs |= bbs << A[i]; } solve(l, mid, bbs); } { BS bbs = bs; for (int i = l; i < mid; ++i) { bbs |= bbs << A[i]; } solve(mid, r, bbs); } } } int main() { for (; ~scanf("%d%d", &N, &K); ) { A.resize(N); for (int i = 0; i < N; ++i) { scanf("%d", &A[i]); } ansAny = 0; ans.assign(N, 0); BS bs; bs[0] = 1; solve(0, N, bs); // cerr<<"ans = ";pv(ans.begin(),ans.end()); int ansCnt = 0; for (int i = 0; i < N; ++i) if (ans[i]) { ++ansCnt; } printf("%d\n", ansAny ? ansCnt : -1); } return 0; }