r = 0 b = 0 L = int(input()) N = int(input()) W = list(map(int,input().split(' '))) W.sort() for i in W: r+=i if r > L: break b+=1 print(b)