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