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