L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() s = 0 i = 0 for a in W: s += a if s > L: break i += 1 print(i)