l = int(input()) n = int(input()) blocks = sorted(list(map(int, input().split()))) tot = 0 count = 0 for i in blocks: if tot + i <= l: tot += i count += 1 print(count)