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