n,m=map(int,input().split())
ans=0
ch=list(map(int,input().split()))
ch.sort()
if m>=sum(ch):
  print(n)
else:
  sum=0
  i=0
  while sum<m and ans!=n:
    sum+=ch[ans]
    ans+=1
    if sum > m:
      ans-=1
      break
  print(ans)
