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