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