L = int(input()) N = int(input()) blocks = sorted([int(i) for i in input().split()]) total = 0 count = 0 for i in blocks: total += i if total > L: break count += 1 print(count)