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

ans = 0

for num in sorted(a):
    if num > k:
        break
    else:
        k -= num
        ans += 1
if k != 0 and ans >= 1:
    ans -= 1
print(ans)
