L = int(input()) N = int(input()) W = sorted(list(map(int, input().split()))) blocks = 0 for w in W: L -= w if L < 0: break else: blocks += 1 print(blocks)