L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() i = 0 while sum(W[:i])<=L and i<=N: i = i+1 print(i-1)