L = int(input()) N = int(input()) W = [int(i) for i in input().split()] W.sort() i = 0 while i < N and L - W[i] >= 0 : L -= W[i] i += 1 print(i)