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