L = int(input()) N = int(input()) W = list(input().split()) W.sort() a = 0 b = L for i in range(N): if b > W[int(i)]: b = b - W[int(i)] a = a + 1 print(a)