import sys

n, x = map(int, input().split())
A = list(map(int, input().split()))
#print(A)

B = sorted(A)
s = sum(A)

if x > s:
    #i = A.index(B[0])
    #print(' '.join(map(str, A[0:i])) + ' ' + str(x-s+B[0]) + ' ' + ' '.join(map(str, A[i+1:n])))
    print(n-1)
    sys.exit(0)
elif x == s:
    #print(' '.join(A))
    print(n)
    sys.exit(0)

for i in range(n-1,0,-1):
    #print(B[0:n-i+1])
    v = s - sum(B[0:n-i+1])
    if v <= x: break

if i == 1:
    if B[0] == x:
        print(1)
    else:
        print(0)
    sys.exit(0)

print(i)
