def count_possible_costs(n, service_costs):
    left, right = 1, max(service_costs) * m
    possible_costs = set()
    
    while left <= right:
        mid = (left + right) // 2
        days = 1
        current_cost = 0
        
        for cost in service_costs:
            if current_cost + cost > mid:
                days += 1
                current_cost = 0
            current_cost += cost
        
        if days <= n:
            possible_costs.add(mid)
            right = mid - 1
        else:
            left = mid + 1
    
    return sorted(possible_costs)

n, m = map(int, input().split())
service_costs = list(map(int, input().split()))

possible_costs = count_possible_costs(n, service_costs)

print(len(possible_costs))
print(*possible_costs)
\
