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)): a += L[i] if a >= weight: print(i) break func()