# your code goes here L=int(input()) N=int(input()) W=list(map(int, input().split())) W.sort() counter = 0 s = 0 for i in W : s += i if s > L : break counter += 1 print(counter)