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