def resolve():

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

    l=list(map(int, input().split()))

    l.sort()

    num=0

    cnt=0

    for i in range(n-1):

        if num+l[i]<=x:

            num+=l[i]

            cnt+=1

    if l[n-1]==x-num:

        cnt+=1

    print(cnt)

resolve()
def resolve():

    import sys

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

    l=list(map(int, input().split()))

    l.sort()

    cnt=0

    for i in range(n):

        if l[i]<=x:

            x-=l[i]

            cnt+=1

        else:

            print(i)

            sys.exit()

    if cnt==n and x>0:

        cnt-=1

    print(cnt)

resolve()
def resolve():
    n, x = list(map(int, input().split()))
    l = list(map(int, input().split()))
    l.sort()
    num = 0
    cnt = 0
    for i in range(n - 1):
        if num + l[i] <= x:
            num += l[i]
            cnt += 1
    if l[n - 1] == x - num:
        cnt += 1
    print(cnt)


resolve()

def resolve():
    import sys

    n, x = list(map(int, input().split()))
    l = list(map(int, input().split()))
    l.sort()
    cnt = 0
    for i in range(n):
        if l[i] <= x:
            x -= l[i]
            cnt += 1
        else:
            print(i)
            sys.exit()
    if cnt == n and x > 0:
        cnt -= 1
    print(cnt)


resolve()

+    import sys + -    num = 0 -    for i in range(n - 1): -        if num + l[i] <= x: -            num += l[i] +    for i in range(n): +        if l[i] <= x: +            x -= l[i] -    if l[n - 1] == x - num: -        cnt += 1 +        else: +            print(i) +            sys.exit() +    if cnt == n and x > 0: +        cnt -= 1