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