# Arup Guha
# 4/5/2025
# Solution to 2017 Jan USACO Silver Problem: Cow Dance Show

import heapq

# Function to return total time of act if stage size is sz
def gettime(cows, sz):

    myq = []

    # Put the first sz cows on stage.
    for i in range(sz):
        heapq.heappush(myq, cows[i])

    # Cows waiting to get on stage.
    for i in range(sz, len(cows)):

        # Time next cow gets off stage.
        nextT = heapq.heappop(myq)

        # Next cow will leave stage at time nextT+cows[i], current time plus dance time.
        heapq.heappush(myq, nextT + cows[i])

    # Keep waiting till each cow gets off stage.
    res = 0
    while len(myq) > 0:
        res = heapq.heappop(myq)

    # Time it took
    return res

    
# Open the file read basic stuff.
myfile = open("cowdance.in", "r")
toks = myfile.readline().split()
n = int(toks[0])
maxTime = int(toks[1])

# Cows in order.
cows = []
for i in range(n):
    cows.append(int(myfile.readline()))

myfile.close()

# Bounds for stage size.
low = 1
high = n

# Go until we converge on a value.
while low < high:

    # Stage size we're trying.
    mid = (low+high)//2

    # This stage isn't big enough.
    if gettime(cows, mid) > maxTime:
        low = mid+1

    # Stage works so answer is no bigger than mid.
    else:
        high = mid

# Write out answer to file.
outfile = open("cowdance.out", "w")
outfile.write(str(low)+"\n")
outfile.close()

        
