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