L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() count = 0 width = 0 i = 0 while i <= N : width += W[i] count += 1 if width >= L : break i += 1 print(count)