L = int(input()) N = int(input()) W = sorted(map(int, input().split())) i = 0 while i < N and W[i] <= L: L -= W[i] i += 1 print(i)