l = int(input()) n = int(input()) w = sorted(map(int, input().split())) x = 0 for i in w: l -= i if l > 0: x += 1 print(x)