from sys import stdin, exit
import itertools
#stdin = open("input.txt")

if __name__ == "__main__":
    N, K = [int(item) for item in stdin.readline().split()]
    li = [int(item) for item in stdin.readline().split()]
    
    li.sort()
    
    if sum(li) == K:
        print(N)
    elif sum(li) < K:
        print(N-1)
    else:
        cumsum = itertools.accumulate(li)
        index = [i for i, item in enumerate(cumsum) if item<=K]
        print(index[-1] + 1)