weight = int(input()) num = int(input()) L = [int(i) for i in input().split()] L.sort() def func(): a = 0 for i in range(len(L)): weight -= L[i] if weight < 0: break print(i) func()