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