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