l = int(input()) n = int(input()) nums = list(map(int,input().split())) nums.sort() x = 0 count = 0 for num in nums: if x + num < l: x += num count += 1 else: break print(count)