|
def read_node(it):
|
|
child_count, meta_count = next(it), next(it)
|
|
|
|
child_sum = sum(read_node(it) for _ in range(child_count))
|
|
own_sum = sum(next(it) for _ in range(meta_count))
|
|
return child_sum + own_sum
|
|
|
|
|
|
it = (int(x) for x in input().split())
|
|
print(read_node(it))
|