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