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