L = int(input()) N = int(input()) W = list(map(int, input().split(' '))) A = 0 R = 0 W = sorted(W) for i in W: A += 1 R += i if R > L: A -= 1 print(A)