L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() ans = 0 for i in range(0, N): if L >= sum(W[0:i+1]): ans+=1 else: break print(ans)