l = int(input()) _ = int(input()) w = sorted(list(map(int, input().split(' ')))) for i in range(len(w)): if sum(w[0:i+1]) <= l: pass else: break print(i)