L = int(input()) N = int(input()) W = sorted([int(elm) for elm in input().split()]) i = 0 while L>=0: L -= W[i] i += 1 print(i)