box = int(input()) n = int(input()) l = [int(x) for x in input().split()] l.sort() sum = 0 a = 0 for i in l: if sum < box: sum += i a += 1 print(a)