L=int(input()) N=int(input()) Ws=sorted( list(map(int, input().split()))) sum = 0 ans = 0 for index, value in enumerate(Ws, 1): sum+=value if (sum>L): break ans = index print ( ans )