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