wd = int(input()) num = int(input()) ls = input().split(" ") bls = [int(i) for i in ls] bls.sort() sm = 0 count = 0 for i in bls: sm += i if sm < wd: count += 1 elif sm == wd: print(count+1) break else: print(count) break