L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() ans = 0 width = 0 for x in W: width += x if width > L: break ans += 1 print(ans)