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