L = int(input()) N = int(input()) W = sorted(list(map(int, input().split()))) b = 0 for i in W: L -= i if L < 0: print(b) break b += 1