In the department that issues official documents, there are employees (including the director), such that:
Each employee (except the director) has one superior.
Each employee has between and subordinate employees.
The superior of my superior is not my direct superior.
The subordinate of my subordinate is not my direct subordinate.
To receive the final approved document, you need to collect a sequence of approvals, starting from one of the subordinates (if any), then the concerned employee or director. Each approval requires paying an official processing fee to that employee.
What is the minimum total official fee required to obtain the final document from the director?

The first line contains , the number of employees in the department. Then follow lines. In the -th line (i = 1, \ldots, N), the data for the -th employee is given as: D_i — the official processing fee, K_i — the number of subordinates, and their numbers. The director has number . All numbers are natural numbers not exceeding .
Output the answer to the problem.
Example 1