L = int(input()) N = int(input()) W = sorted(map(int, input().split())) c = 0 while W: L -= W.pop(0) if L < 0: break c += 1 print(c)