L = int(input()) N = int(input()) W = sorted(map(int, input().split())) C = 0 for w in W: L -= w if L < 0: break C += 1 print(C)