L = int(input()) N = int(input()) blocks = sorted(map(int,input().split())) w = 0 for i, block in enumerate(blocks, 1): w += block if w > L : print(i-1) break else: print(N)