L = int(input()) N = int(input()) W = list(map(int,input().split())) count = 0 W.sort() for w_i in W: if L - w_i >= 0: L -= w_i count += 1 print(count)