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