L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() T = 0 c = 0 for i in range(N): T += W.pop(0) c += 1 if L <= T: break print(c)