N, M = map(int, raw_input().split())
a = map(int, raw_input().split())

sorted(a)

sum = 0
itr = 0
for i in range(N):
  sum = sum+a[i]
  if sum >= M:
    itr = i
    break
    
if sum < M:
  print N-1
elif sum == M:
  print itr+1
elif sum > M:
  print itr