#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 5000;

int N;
int K;

int A[MAX_N];
bool dp1[MAX_N][MAX_N + 1], dp2[MAX_N][MAX_N + 1];

bool isNeeded(int i);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> K;

    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    sort(A, A + N);
    if (A[0] <= K)
        dp1[0][A[0]] = 1;
    dp1[0][0] = 1;

    for (int j = 1; j < N; j++) {
        for (int k = 0; k < K; k++) {
            if (k >= A[j]) {
                dp1[j][k] = dp1[j - 1][k] || dp1[j - 1][k - A[j]];
            } else {
                dp1[j][k] = dp1[j - 1][k];
            }
        }
    }
    if (A[N - 1] <= K)
        dp2[N - 1][A[N - 1]] = 1;
    dp2[N - 1][0] = 1;
    for (int j = N - 2; j >= 0; j--) {
        for (int k = 0; k < K; k++) {
            if (k >= A[j]) {
                dp2[j][k] = dp2[j + 1][k] || dp2[j + 1][k - A[j]];
            } else {
                dp2[j][k] = dp2[j + 1][k];
            }
        }
    }

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < K; j++) {
            cout << "i = " << i << ", j = " << j << ",dp1 = " << dp1[i][j] << "\n";
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < K; j++) {
            cout << "i = " << i << ", j = " << j << ",dp2 = " << dp2[i][j] << "\n";
        }
    }
    

    for (int i = 0; i < N; i++) {
        cout << "A[i] = " << A[i] << ", isNeeded = " << isNeeded(i) << "\n";
    }
    */

    int ans = 0;
    int lmax, lmin;
    if (isNeeded(0)) {
        ans = 0;
    } else if (!isNeeded(N - 1)) {
        ans = N;
    } else {
        lmax = N - 1;
        lmin = 0;
        while (true) {
            int lmid = (lmin + lmax) / 2;
            //cout << "lmin = " << lmin << ", lmax = " << lmax << ", lmid = " << lmid << ", isNeeded = " << isNeeded(lmid) << "\n";
            if (lmid == lmin || lmid == lmax) {
                ans = lmin + 1;
                break;
            }
            if (isNeeded(lmid)) {
                lmax = lmid;
            } else {
                lmin = lmid;
            }
        }
    }

    cout << ans << "\n";

    return 0;
}

bool isNeeded(int i)
{
    if (i != 0 && i != N - 1) {
        for (int s = max(0, K - A[i]); s < K; s++) {
            for (int t = 0; t <= s; t++) {
                //cout << "s = " << s << ", t = " << t << ",dp1 = " << dp1[i - 1][t] << ", dp2 = " << dp2[i + 1][s - t] << "\n";
                if (dp1[i - 1][t] && dp2[i + 1][s - t]) {
                    return true;
                }
            }
        }
        return false;
    } else if (i == 0) {
        if (N == 1) {
            if (A[0] >= K) {
                return true;
            } else {
                return false;
            }
        }
        for (int s = max(0, K - A[0]); s < K; s++) {
            if (dp2[1][s]) {
                return true;
            }
        }
        return false;
    } else {
        for (int s = max(0, K - A[N - 1]); s < K; s++) {
            if (dp1[N - 2][s]) {
                return true;
            }
        }
        return false;
    }
}


Measured memory_bytes: 52528