l = int(input()) n = int(input()) w = list(map(int, input().split())) w.sort() a = [] for i in w: a.append(i) if sum(a) > l: del(a[-1]) break print(len(a))