L = int(input()) N = int(input()) W = [int(i) for i in input().split()] W.sort() ans = 0 for w in W: if L - w < 0: break L -= w ans += 1 print(ans)