L = int(input())
N = int(input())
W = [int(x) for x in input().split(' ')]

W.sort()
cnt = 0

while cnt < N and L >= W[cnt]:
	L -= W[cnt]	
	cnt += 1
print(cnt)