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