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