import bisect N, M = map(int, input().split()) C = list(sorted(list(map(int, input().split())))) S = [0] for c in C: S.append(S[-1] + c) p = bisect.bisect_right(S, M) print(p - 1)