Official Approval#2996

Official Approval

1 second
64 megabytes
Very easy

In the department that issues official documents, there are employees (including the director), such that:

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?

Input

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

Output the answer to the problem.

Examples

Example 1

Loading
Loading