L = int(input()) N = int(input()) W = list(map(int, input().split(" "))) W.sort() ans = 0 for i in W: if i <= L: L -= i ans += 1 print(ans)