peterverebics/CodeNet_Python_118 huggingface dataset:
N, x = map(int, input().split())
children = sorted(list(map(int, input().split())))

count = 0
for child in children:
    if x >= child:
        x -= child
        count += 1
    else:
        break
if x == 0:
    print(count)
else:
    if count != 0:
        print(count - 1)
    else:
        print(0)
N,x=input().split()
X=int(x)
n=int(N)
y=0
A = [int(i) for i in input().split()]
A.sort()
for z in range(n):
  y+=A[z]
  if y>=X:
    print(z+1)
    break
from itertools import accumulate
from bisect import bisect_left


def main():
    children, cookies = map(int, input().split())
    target = sorted(list(map(int, input().split())))
    sum_target = sum(target)
    if sum_target < cookies:
        print(children - 1)
    elif cookies < target[0]:
        print(0)
    else:
        accumulate_target = list(accumulate(target))
        print(bisect_left(accumulate_target, cookies) + 1)


if __name__ == '__main__':
    main()
n, x = map(int, input().split())
a = list(map(int, input().split()))
original = x
a.sort()

cnt = 0
for i in a:
    if x >= i:
        x -= i
        cnt += 1
    else:
        break
if original != sum(a) and cnt == x:
    cnt -= 1

print(cnt)
N, x = map(int, input().split())
a = list(map(int, input().split()))

sorted_a = sorted(a)
cont = 0

for i in range(N):
    if x >= sorted_a[i]:
        cont += 1
        x = x - sorted_a[i]
if x != 0:
    cont = cont -1
print(cont)
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for i in range(n):
    x = x - a[i]
    if x >= 0:
        continue
    else:
        print(i)
        break
if x >= 0:
    print(i+1)
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
for i in range(n):
    if x >= a[i]:
        ans += 1
        x -= a[i]
    else:
        break
if x > 0 and ans != 0:
    ans -= 1
print(ans)
# A - Candy Distribution Again
count = 0
N, x = map(int, input().split())
A = input().split()
A.sort()
A_i = [int(s) for s in A]
if(sum(A_i) == x):
    print(N)
else:
    for i in range(N):
        if(i != N-1):
            x -= A_i[i]
            if(x >= 0):
                count += 1
    print(count)
# 27

n, x = map(int, input().split())
a = list(map(int, input().split()))
num = 0
for i in range(len(a)-1):
    if x >= a[i] :
        num += 1
        x -= a[i]
if x == a[-1]:
    num += 1
print(num)
n,x = map(int,input().split())
a = [int(x.strip()) for x in input().split()]
a_sorted = sorted(a)
ch,ans = 0,0
for i in range(n):
  ch = sum(a_sorted[:i+1])
  if ch < x:
    ans += 1
  elif ch == x:
    ans += 1
    break
  else:
    break
if ans != 0 and ch != x:
  ans = ans-1
print(ans)
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
cnt = 0
for elem in a:
  if x >= elem:
    cnt += 1
    x -= elem
  else:
    break
print(cnt)
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if x < a[0]:
    print(0)
else:
    for i in range(n):
        x = x - a[i]
        if x > 0:
            continue
        elif x == 0:
            print(i+1)
            break
        else:
            print(i-2)
            break
if x > 0 and x > a[0]:
    print(n-1)
N, x = map(int, input().split())
a = list(map(int, input().split()))

# 小さい数から配っていくと子供の人数を最大化できる
a = sorted(a)

leftCandy = 0
childrenCnt = 0
for i in range(len(a)):
  leftCandy = x - a[i]
  if leftCandy >= 0:
    childrenCnt += 1

if leftCandy > 0:
  print(N-1)
else:
  print(childrenCnt)
from itertools import accumulate
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
c = list(accumulate(a))
ans = sum([1 for i in c if i <= x])
if not ans:
  print(ans)
else:
  print(ans if x in list(c) else ans - 1)
N,x = map(int,input().split())
a=list(map(int,input().split()))

a.sort()

ans=0
for i in range(N):
    if x >= a[i]:
        ans+=1
        x-=a[i]
    else:
        break
if x != 0:
    ans -= 1
print(ans)
n,x = map(int,input().split())
a = list(map(int,input().split()))

Slist = sorted(a)
cnt = 0
Sum = 0

for i in range(len(Slist)):
  Sum += Slist[i]
  if x>=Sum:
    cnt +=1
  else:
    break
print(cnt)
N, X = map(int, input().split())
lists = list(map(int, input().split()))

if X - sum(lists) > 1:
    print(len(lists) - 1)
    exit()

count = 0
for num in sorted(lists):
    X -= num
    if X >= 0:
        count += 1
        if num == lists[-1]:
            break
        continue
    break
print(count)
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

# print(N, x)
# print(A)

count = 0
for i in range(N):
    if x >= A[i]:
        count += 1
        x -= A[i]
if count > 0 and x > 0:
    count -= 1

print(count)
import numpy as np

n, x = map(int, input().split())
a = np.array(list(map(int, input().split())))
a = np.sort(a)

cnt = 0
for a_ in a:
    cnt += 1
    if a_ <= x:
        x -= a_
    elif a_ > x:
        break
print(cnt if x == 0 else cnt - 1)
n,x = map(int,input().split())
a_list = list(map(int,input().split()))
a_list.sort()
count = 0
for i in range(n):
    if a_list[i] <= x:
        count += 1
        x = x-a_list[i]
    else:
        break
if x > 0:
    if count == 0:
        print(0)
    else:
        print(count-1)
else:
    print(count)
N, x = map(int, input().split())
a = list(map(int, input().split()))

count = 0

for v in a:
    if v <= x and x >= 0:
        count +=1
        x -= v
        
if x != 0:
    count = count - 1

print(count)
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

count = 0
for ai in a:
    if ai <= x:
        x -= ai
        count += 1
    else:
        break

if x > 0:
    count -= 1

print(count)
try:
  N, x = map(int, input().split())
  a = list(map(int, input().split()))
  a_ = sorted(a)
  cnt = 0
  for i in a_:
      if i<=x:
          cnt += 1
          x = x-i
      else:
          break
  print(cnt)
except EOFError:
  pass
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))

child = 0
candy = 0

print(a)

for i in a:
    candy += i
    if candy <= x:
        child += 1

if sum(a) < x:
    child -= 1

print(child)
n,x = map(int,input().split())
line = sorted(list(map(int,input().split())))
count = 0
if sum(line) < x:
  count = n - 1
elif sum(line) == x:
  count = n
else:
  for i in range(n):
    left = x - line[i]
    if left >= 0:
      count += 1
    else:
      break
print(count)
N, x = map(int, input().split())
a = list(map(int, input().split()))

# 小さい数から配っていくと子供の人数を最大化できる
a = sorted(a)

leftCandy = 0
childrenCnt = 0
for i in range(len(a)):
  leftCandy = x - a[i]
  if leftCandy >= 0:
    childrenCnt += 1

print(childrenCnt)
n,x = map(int,input().split())
a = sorted(map(int,input().split()))
c=0
d=0
for i in a:
    if c+i<=x:
        c+=i
        d+=1
else:
    if c<x:
        d-=1
print(d)
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
ans=0
for i in range(n):
    if x>=a[i]:
        ans+=1
        x-=a[i]
    else:
        break
if ans == n:
    if x!=0:
        ans-=1
print(x)
print(ans)
n,x=map(int,input().split())
a=sorted([int(i)for i in input().split()])
res=0
if sum(a)==x:
    res=n
else:
    for i in range(n):
        if sum(a[:i])<=x:res=len(a[:i])-1
print(max(0,res))
A,B=list(map(int,input().split()))
C=list(map(int,input().split()))
C.sort()
ans = 0
for i in C:
    if B >= i:
        ans+=1
        B-=i
    else:
        print(ans)
        exit()
print(ans)
n,x = map(int,input().split())
a = sorted(map(int,input().split()))
c=0
for i in a:
    if i<=x:
        x-=i
        c+=1
else:
    if x>0:
        c-=1
print(max(0,c))
n, k = map(int, input().split())

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

sum = 0
ans = 0
a.sort()

for i in range(n):
    sum += a[i]
    if sum <= k:
        ans += 1
    else:
        break

print(ans)
N, x = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])

ans = 0

if sum(a) == x:
    ans = N
else:
    for i in range(N):
        if x > a[i]:
            x -= a[i]
            ans += 1

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

answer = 0
id = -1

for idx, a in enumerate(sorted(li_a)):
    id = idx
    if x >= a:
        answer += 1
        x -= a
    else:
        break
if x == 0 or answer == 0:
    print(answer)
else:
    if id == (n -1):
        print(answer - 1)
    else:
        print(answer)
N, x = [int(z) for z in input().split()]
children = [int(z) for z in input().split()]

children.sort()
cnt = 0

for i in children:
    if x - i < 0:
        break
    else:
        x -= i
        cnt += 1
        
print(cnt)
[N, x] = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
count = 0
i = 0
while x >= 0 and i <= len(a):
  x -= a[i]
  if i == len(a)-1:
    if x != a[i]:
      break
  if x >= 0:
    count += 1
  i += 1
  
print(count)
N,x = map(int,input().split())
a = list(map(int,input().split()))

a = sorted(a, reverse = False)

count = 0
if sum(a) < x:
    count = N -1
else:
    for i in a:
        A = x - i
        if A < 0:
            count -=1
            break
        elif A == 0:
            count += 1
            break
        count+=1
if count == -1:
    count = 0
print(count)
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
c = 0
rx = x
for i in range(N):
  if a[i] > rx:
    print(c)
    exit()
  c += 1
  rx -= a[i]
print(N)
N,M = map(int,input().split())
L = input().split()

L = sorted(L)

total = 0
i = 0
while M > 0 and i < N:
    M -= int(L[0])
    L.pop(0)
    total += 1
    i += 1

print(total)
N,x=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
for i in range(len(A)):
  if x-A[i]<0:
    break
  else:
    x-=A[i]
print(i)
n,x = map(int,input().split())
al = list(map(int,input().split()))
al.sort()
c = 0
for a in al:
  if x >= a:
    c += 1
    x -= a
if x > 0 and c > 0:
  c -= 1
print(c)
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cnt = 0
j = 0
for i in range(N):
  if (cnt + a[i]) > x:
    break
  cnt += a[i]
  j += 1
if j == len(a):
  j -= 1
print(j)
num_children, num_snacks = list(map(int, input().split(' ')))
children = list(map(int, input().split(' ')))
children.sort()
print(children)

count = 0
for i in range(num_children+1):
  if num_snacks >= sum(children[:i+1]):
    count += 1
  else:
    break
print(count)
N,x = map(int,input().split())

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

a.sort()

sum =x
cnt=0

for i in range(N):
    if x -a[i] >= 0:
        cnt+=1
        x = x-a[i]

if x >0:
    if cnt >0:
        cnt = cnt-1
        
print(cnt)
import math


# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N, x = invr()

a = inlist()
a = sorted(a)
c = 0
for i in a:
    if i <= x:
        c += 1
        x -= i
if x > 0 and c > 0:
    c -= 1
print(c)
N, x = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])

ans = 0

if sum(a) <= x:
  	ans = N - 1
elif sum(a) == x:
    ans = N
else:
    for i in range(N):
        if x >= a[i]:
            x -= a[i]
            ans += 1

print(ans)
N, x = map(int, input().split())
a = list(map(int, input().split()))

a = sorted(a)
ans = 0

for i in range(N):
    if a[i] <= x:
        x -= a[i]
        ans += 1

if x > 0 and ans > 0:
    ans -= 1
    print(ans)
elif x == 0:
    print(ans)
else:
    print(0)
n, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
pos = -1
for i in range(0, n):
    x -= a[i]
    if x < 0:
        pos = i
        break
if pos == -1:
    print(n)
else:
    print(pos)
import sys
input = sys.stdin.readline

def main():
    N, x = map(int, input().split())
    a_list = list(map(int, input().split()))
    if sum(a_list) == x:
      print(N)
      sys.exit()
    for i, a in enumerate(sorted(a_list), start=1):
        x -= a
        if x < 0:
            break
    if x >= 0:
        print(i)
    else:
        print(i-1)
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = []
num = a[0]
i = 1

while num <= x:
    num += a[i]
    if x - a[i] > 0:
        x -= a[i]
        b.append(a[i])
        i += 1
    else:
        b.append(max(0,a[i]))
        break

print(a)
print(b)
print(num)

ans = 0
for i in range(min(len(a),len(b))):
    if a[i] == b[i]:
        ans += 1
print(ans)
n, x = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)
ans = 0
for a in A:
    if x - a >= 0:
        x -= a
        ans += 1
if 0 < x:
    for a in A:
        x -= a
        ans -= 1
        if x <= 0:
            break

print(max(ans, 0))
N,X=map(int,input().split())
ai=list(map(int,input().split()))
ai.sort()
sum_of_the_candy=0
ans=0
if sum(ai)==X:
	ans=N
elif sum(ai)<X:
	ans=N-1
else:
	for i in range(N):
		sum_of_the_candy=sum_of_the_candy+ai[i]
		if sum_of_the_candy < X:
			ans = ans +1
		else:
			break
print(ans)
n, x = map(int, input().split())
A = sorted([int(i) for i in input().split()])
# print(A)
cnt = 0
for e in A:
    if e <= x:
        x = x - e
        cnt += 1
if x == 0 or cnt == 0:
    print(cnt)
else:
    print(cnt-1)
import sys
input=sys.stdin.readline
from bisect import bisect_right
import itertools

N,X= map(int,input().split())
A=list(map(int,input().split()))

A.sort()
Acum = list(itertools.accumulate(A))
print(Acum)
answer = bisect_right(Acum,X)
if answer == N:
    if Acum[-1] < X:
        answer -= 1
print(answer)
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(n-1):
  x=x-a[i]
  if x<0:
    x=x+a[i]
  else:
    ans+=1
a.sort(reverse=True,key=int)
ansr=0
for i in range(n-1):
  x=x-a[i]
  if x<0:
    x=x+a[i]
  else:
    ansr+=1
print(max(ans,ansr))
N, x = map(int, input().split())
A = [int(i) for i in input().split()]

A.sort()
ans = []
for i in A:
	x -= i
	#print(ans, x)
	if x <= 0:
		break
	ans.append(i)

if x > 0:
	print(len(ans)-1)
else:
	print(len(ans))
n,x = map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
a.sort()

for i in range(n):
  if x - a[i] >= 0:
    cnt += 1
    x -= a[i]
if x != 0:
  cnt -= 1

print(max(0,cnt))
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
count = 0
if x < a[0]:
    print(0)
    exit()

for i in range(N):
    if x >= a[i]:
        x = x - a[i]
        count += 1
    else:
        break
if x > 0:
    print(count - 1)
else:
    print(count)
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
ans=0
for i in a:
    if i>x:
        break
    else:
        n-=i
        ans+=1
print(ans)
# 27

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

for i in range(len(a)):
    if i != len(a) - 1:
        if x >= a[i] :
            num += 1
            x -= a[i]
    elif x == a[i]:
        num += 1

print(num)
import sys
n,x=map(int,input().split())
N=list(map(int,input().split()))
K=sorted(N,reverse=True)
if sum(K)<=x:
  print(n)
  sys.exit()
for i in range(1,n+1):
  if sum(K)-K[0]<=x:
    print(n-i)
    sys.exit()
  else:
    K.pop(0)
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
s=0
while s<n-1:
  if m>=a[s]:
    m-=a[s]
    s+=1
  else:break
print(s)
n,x = map(int,input().split())
a = sorted(map(int,input().split()))
c=0
d=0
for i in a:
    if c+i<x:
        c+=i
        d+=1
else:
    if c<x:
        d-=1
print(d)
n,x = map(int,input().split()) 
A= list(map(int,input().split())) 
A.sort()
a_sum=0  
for i in range(n):
    a_sum+= A[i]
    if x<a_sum:
        print(i)
        exit() 

print(n)
num_children, num_snacks = list(map(int, input().split(' ')))
children = list(map(int, input().split(' ')))
children.sort()

count = 0
for i in range(num_children):
  if num_snacks >= sum(children[:i+1]):
    count += 1
print(count)
N,x = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
S = 0
count = 0

for i in range(N):
  S += A[i]
  
if S < x:
  print(N-1)
  exit()
else:
  for i in range(N):
    b = x - A[i]
    if b > 0:
      count += 1
      x -= A[i]
    elif b == 0:
      count += 1
      exit()
    else:
      exit()
  print(count)
n, x = map(int, input().split())
l = sorted(list(map(int, input().split())))
if sum(l) <= x:
    print(n)
else:
    for i in range(n):
        print(x)
        if x <= 0:
            break
        x -= l[i]
    print(i)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np


def main(n, x, a):
  cnt = 0
  for i in a:
    x -= i
    if x <= 0:
      break
    elif i == a[-1] and x > 0:
      break
    cnt += 1
  return cnt

n, x = map(int, readline().split())
a = np.sort(np.array(readline().split(), np.int64))
print(main(n, x, a))
N, x = [int(z) for z in input().split()]
children = [int(z) for z in input().split()]

children.sort()
sum = 0

for i in range(N):
    sum += children[i]
    if sum >= x:
        print(i + 1)
        break
    elif i == N - 1:
        print(N - 1)
import sys
input = sys.stdin.readline

def main():
    N, x = map(int, input().split())
    a_list = list(map(int, input().split()))
    ans = 0
    for a in sorted(a_list):
        if a <= x:
            ans += 1
            x -= a
        else:
            break
    if ans == N:
        print(ans - 1)
    else:
        print(ans)

if __name__ == '__main__':
    main()
N, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
children = [0] * N
a.sort()
kashi = 0
while kashi < x:
    for i in range(0,N):
        kashi += a[i]
        children[i] += 1
        if kashi > x:
            kashi -= a[i]
            children[i] -= 1
            break
    if kashi == 0:
        break
print(N - children.count(0))
if __name__ == "__main__":
    n, x = map(int, input().split())
    a = list(map(int, input().split()))

    if sum(a) == x:
        print(n)
        exit()

    a.sort()

    ans = 0
    tmp = 0
    for aa in a:
        if tmp < x and aa <= x-tmp:
            tmp += aa
            ans += 1
        if tmp == x:
            print(ans)
            exit()
    if ans > 0:
        ans -= 1

    print(ans)
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
res = 0
for a in A:
    if a > X:
        break
    res += 1
    X -= a
if X > 0:
    res -= 1
print(max(res, 0))
N, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
while len(a) != 0:
    next = min(a)
    a.remove(min(a))
    if x < next:
        break
    x -= next
    cnt += 1

cnt = 1 if cnt == 0 else cnt
print(cnt if x == 0 else cnt-1)
N, x = map(int,input().split())

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

al.sort()

cnt = 0

for a in al:

  x -= a

  if x < 0:

    break

  cnt += 1

if x != 0 and cnt >= 1:
  print(cnt-1)
else:
  print(cnt)
n, k =map(int,input().split())
data = list(map(int,input().split()))
data = sorted(data)
cnt = 0
for var in data:
    if var <= k:
        cnt += 1
        k = k-var
       
    else:
        continue
print(cnt)
n , x = map(int , input().strip().split())
a  = list(map(int , input().strip().split()))
a.sort()
count = 0

for i in a:
  if x - i < 0:
    break
  x -= i
  count += 1

print(count)
try:
  N, x = map(int, input().split())
  a = list(map(int, input().split()))
  a_ = sorted(a)
  cnt = 0
  for i in a_:
      if i<=x:
          cnt += 1
          x = x-i
  print(cnt)
except EOFError:
  pass
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
S = 0
ans = 0
for i in range(N):
  S += A[i]
  if S <= X:
    ans += 1
  else:
    break
if S > X:
  ans = N-1
print(ans)
def main():
    n, x = map(int, input().split())
    num_list = list(map(int, input().split()))

    ans = 0
    num_list.sort()

    for num in num_list:
        if x - num >= 0:
            x -= num
            ans += 1
        else:
            break

    if x != 0:
        ans -= 1

    print(ans)


if __name__ == '__main__':
    main()
N, x = [int(z) for z in input().split()]
children = [int(z) for z in input().split()]

children.sort()
cnt = 0

for i in children:
    cnt += 1
    if x - i < 0:
        break
    else:
        x -= i

print(cnt)
n,x = map(int,input().split())
a = sorted(map(int,input().split()))
c=0
d=0
for i in a:
    if c+i<=x:
        c+=i
        d+=1
else:
    if 0<c<x:
        d-=1
print(d)
import sys
n,x=map(int,input().split())
N=list(map(int,input().split()))
K=sorted(N,reverse=True)
if sum(K)<x:
  print(n-1)
  sys.exit()
if sum(K)==x:
  print(n)
  sys.exit()
for i in range(1,n+1):
  if sum(K)-K[0]==x:
    print(n-i)
    sys.exit()
  if sum(K)-K[0]<x:
    print(n-i-1)
    sys.exit()
  else:
    K.pop(0)
N,x = map(int,input().split())
a = list(map(int,input().split()))

a.sort()

count = 0
resid = x
for i in range(N):
    if a[i] <=resid:
        count += 1
        resid -= a[i]
    else:
        break
if resid > 0:
    count -= 1
print(count)
n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

ans = 0
i = 0

for i in a:
    if i > x:
        break
    else:
        x -= i
        ans += 1

if x != 0 and ans != 0:
    ans -= 1

print(ans)
N,x = list(map(int,input().split()))
A = list(sorted(list(map(int,input().split()))))
for i in range(N,0,-1):
    if sum(A[:i]) == x:
        print(i)
        break
    elif sum(A[:i]) < x:
        print(i-1)
        break
else:
  print(0)
N, x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
count = 0
for i in range(N):
    x = x - a[i]
    if x >= 0:
        count += 1  

print(count)
N,x = map(int, input().split())
A = list(map(int, input().split()))

A.sort()

ans = 0
for i in range(N):
  if x > A[i]:
    ans += 1
    x -= A[i]
  elif x == A[i]:
    print(ans+1)
    break
  elif i+1 == N:
    print(ans -1)
    break
  else:
    print(ans)
    break
else:
  print(ans-1)
N,X=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=0
if X<min(a):
    print(0)
else:
    for i in range(0,N):
        if X>=a[i]:
            X=X-a[i]
            b+=1
        else:
            break
    if X!=0:
        print(b-1)
    else:
        print(b)
#!/usr/bin/env python3

N, x = [int(x) for x in input().split(" ")]
A = sorted([int(x) for x in input().split(" ")])

ans = 0
for a in A:
    if x < a:
        break
    ans += 1
    x -= a

if x > 0 and ans > 0:
    ans -= 1

print(ans)
N, x = map(int,input().split())
a = sorted([int(i) for i in input().split()])
count = 0
if sum(a) == x:
    print(len(a))
else:
    for i in a:
        if x-i<0:
            break
        count+=1
    if count == N:
        print(N-1)
    else:
        print(count)
N,x = map(int,input().split())
hito = input().split()
poo = [hito]
zyun = sorted(hito)

ok = 0
for i in range(len(hito)):
	if x-int(zyun[i])>=0:
		ok+=1
		if ok == len(hito):
			print(ok)
			exit()
	else:
		print(ok)
		exit()
#coding:utf-8
n, x = map(int, input().split())
a = list(map(int, input().split()))
child = sorted(a)
ans = 0
candy = 0

for i in range(n):
    candy += child[i]
    if candy == x:
        print(i+1)
        exit()
    elif candy > x:
        print(0)
        exit()
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
count = 0

for i in a:
  if x - i >= 0:
    x -= i
    count += 1
if x > 0 and count != 0  and x > sum(a):
  count -= 1
print(count)
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
S = 0
ans = 0
for i in range(N):
  S += A[i]
  if S <= X:
    ans += 1
  else:
    break
print(ans)
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(n):
  if a[i]<=x:
    x=x-a[i]
    ans=ans+1
if x>0:
  ans=ans-1
print(ans)
#Candy Distribution Again
n,x = map(int, input().split())
s= list(map(int,input().split()))

s.sort()
s.reverse
if s[0]>x:
    ans=1
else :
    ans=0
for i in s:
    x=x-i
    if x>=0:
        ans+=1
    else :
        break
if x>0:
    ans-=1
    
print(ans)
n, x = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)

ans = 0
for i in range(n):
    if x - a[i] >= 0:
        ans += 1
        x = x - a[i]
    else:
        break
if x > 0:
    ans -= 1
if ans < 0:
    ans = 0
print(ans)