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