L = int(input()) N = int(input()) W = sorted(map(int, input().split())) count_i = 0 sum_i = 0 for i in range(N): j = sum_i + W[i] if j <= L: sum_i = j else: break count_i += 1 print(count_i)