# Arup Guha
# 7/21/2025
# Solution to USACO Problem Cow Dance (Jan 2017 Silver)

import heapq

# Returns the time for the cows dancing on a stage with size stage.
def f(cows, stage):

    res = 0

    # Put the first stage dancers on stage.
    myheap= []
    for i in range(stage):
        heapq.heappush(myheap, cows[i])
        res = max(res, cows[i])

    # The rest of the cows get on stage.
    for i in range(stage, len(cows)):

        # Time next cow gets off stage.
        nextCow = heapq.heappop(myheap)

        # Time new cow will get off stage.
        heapq.heappush(myheap, nextCow+cows[i])

        # Update our answer.
        res = max(res, nextCow+cows[i])

    # This is the time the last cow gets off stage.
    return res

    
# Open file, read first line.
myf = open("cowdance.in", 'r')
toks = myf.readline().split()
n = int(toks[0])
maxT = int(toks[1])

# Read cowdance times.
cows = []
for i in range(n):
    x = int(myf.readline().strip())
    cows.append(x)

myf.close()

low = 0
high = n-1

# Go until we converge on a value.
while low < high:

    mid = (low+high)//2

    thisT = f(cows, mid)

    # Took too long the stage needs to be bigger.
    if thisT > maxT:
        low = mid+1

    # This is good enough so the answer can't be higher than this.
    else:
        high = mid


outf = open("cowdance.out", 'w')
outf.write(str(low)+"\n")
outf.close()
