from collections import defaultdict

import bisect

import sys

def inpl(): return [int(i) for i in input().split()]

def search(a,j):

    if D[j]:

        if D[j] == 1:

            return True

        else:

            return False

    H = defaultdict(lambda: 0)

    H[0] = True

    for i in a:

        for ni in list(H.copy().keys()):

            if ni + i < K-j:

                H[ni+i] = True

                continue

            elif ni + i <= K-1:

                D[j] = 1

                return True

    D[j] = -1

    return False



N, K = inpl()

A = inpl()

A.sort()

A = A[:bisect.bisect_left(A,K)]

M = len(A)

D = defaultdict(lambda: 0)

if sum(A) < K:

    print(M)

    sys.exit()

if sum(A) == K:

    print((0))

    sys.exit()

lo = -1

hi = M

while hi - lo > 1:

    me = (hi+lo)//2

    B = A[:me] + A[me+1:]

    if search(B, A[me]):

        hi = me

    else:

        lo = me

print(hi)
from operator import or_

from functools import reduce

import sys

readline = sys.stdin.readline



def check(a, l, r):

    if (reduce(or_, [r*(1<<k) for k in range(K) if l & (1<<k)])&filt).bit_length() + a > K:

        return True

    else:

        return False



N, K = list(map(int, readline().split()))

A = list(map(int, readline().split()))

A = [a for a in A if a < K]

A.sort()

filt = (1<<K) - 1

M = len(A)

A = [None]+A

dpl = [0]*(M+2)

dpr = [0]*(M+2)

dpl[0] = 1

dpr[M+1] = 1



for i in range(1, M+1):

    dpl[i] = dpl[i-1]*(1<<A[i])&filt |dpl[i-1]



for i in range(M, 0, -1):

    dpr[i] = dpr[i+1]*(1<<A[i])&filt |dpr[i+1]

    

ok = M+1

ng = 0

while abs(ok - ng) > 1:

    med = (ok+ng)//2

    if check(A[med], dpl[med-1], dpr[med+1]):

        ok = med

    else:

        ng = med

print(ng)

from collections import defaultdict
import bisect
import sys


def inpl():
    return [int(i) for i in input().split()]


def search(a, j):
    if D[j]:
        if D[j] == 1:
            return True
        else:
            return False
    H = defaultdict(lambda: 0)
    H[0] = True
    for i in a:
        for ni in list(H.copy().keys()):
            if ni + i < K - j:
                H[ni + i] = True
                continue
            elif ni + i <= K - 1:
                D[j] = 1
                return True
    D[j] = -1
    return False


N, K = inpl()
A = inpl()
A.sort()
A = A[: bisect.bisect_left(A, K)]
M = len(A)
D = defaultdict(lambda: 0)
if sum(A) < K:
    print(M)
    sys.exit()
if sum(A) == K:
    print((0))
    sys.exit()
lo = -1
hi = M
while hi - lo > 1:
    me = (hi + lo) // 2
    B = A[:me] + A[me + 1 :]
    if search(B, A[me]):
        hi = me
    else:
        lo = me
print(hi)

from operator import or_
from functools import reduce
import sys

readline = sys.stdin.readline


def check(a, l, r):
    if (
        reduce(or_, [r * (1 << k) for k in range(K) if l & (1 << k)]) & filt
    ).bit_length() + a > K:
        return True
    else:
        return False


N, K = list(map(int, readline().split()))
A = list(map(int, readline().split()))
A = [a for a in A if a < K]
A.sort()
filt = (1 << K) - 1
M = len(A)
A = [None] + A
dpl = [0] * (M + 2)
dpr = [0] * (M + 2)
dpl[0] = 1
dpr[M + 1] = 1
for i in range(1, M + 1):
    dpl[i] = dpl[i - 1] * (1 << A[i]) & filt | dpl[i - 1]
for i in range(M, 0, -1):
    dpr[i] = dpr[i + 1] * (1 << A[i]) & filt | dpr[i + 1]
ok = M + 1
ng = 0
while abs(ok - ng) > 1:
    med = (ok + ng) // 2
    if check(A[med], dpl[med - 1], dpr[med + 1]):
        ok = med
    else:
        ng = med
print(ng)

-from collections import defaultdict -import bisect +from operator import or_ +from functools import reduce - -def inpl(): -    return [int(i) for i in input().split()] +readline = sys.stdin.readline -def search(a, j): -    if D[j]: -        if D[j] == 1: -            return True -        else: -            return False -    H = defaultdict(lambda: 0) -    H[0] = True -    for i in a: -        for ni in list(H.copy().keys()): -            if ni + i < K - j: -                H[ni + i] = True -                continue -            elif ni + i <= K - 1: -                D[j] = 1 -                return True -    D[j] = -1 -    return False +def check(a, l, r): +    if ( +        reduce(or_, [r * (1 << k) for k in range(K) if l & (1 << k)]) & filt +    ).bit_length() + a > K: +        return True +    else: +        return False -N, K = inpl() -A = inpl() +N, K = list(map(int, readline().split())) +A = list(map(int, readline().split())) +A = [a for a in A if a < K] -A = A[: bisect.bisect_left(A, K)] +filt = (1 << K) - 1 -D = defaultdict(lambda: 0) -if sum(A) < K: -    print(M) -    sys.exit() -if sum(A) == K: -    print((0)) -    sys.exit() -lo = -1 -hi = M -while hi - lo > 1: -    me = (hi + lo) // 2 -    B = A[:me] + A[me + 1 :] -    if search(B, A[me]): -        hi = me +A = [None] + A +dpl = [0] * (M + 2) +dpr = [0] * (M + 2) +dpl[0] = 1 +dpr[M + 1] = 1 +for i in range(1, M + 1): +    dpl[i] = dpl[i - 1] * (1 << A[i]) & filt | dpl[i - 1] +for i in range(M, 0, -1): +    dpr[i] = dpr[i + 1] * (1 << A[i]) & filt | dpr[i + 1] +ok = M + 1 +ng = 0 +while abs(ok - ng) > 1: +    med = (ok + ng) // 2 +    if check(A[med], dpl[med - 1], dpr[med + 1]): +        ok = med -        lo = me -print(hi) +        ng = med +print(ng)