L = int(input()) N = int(input()) W = sorted(map(int, input().split()))[::-1] c = 0 while L > 0: L -= W.pop() c += 1 print(c-1)