#数字のブロック L = int(input()) N = int(input()) W = list(map(int , input().split())) W.sort() sum = 0 count = 0 for i in W: sum += i if sum > L: break count += 1 print(count)