The scientific project consists of tasks, each executed on one of processors of a supercomputer. Tasks may run concurrently, but some can only start after certain other tasks are completed. For each task, its execution time and the list of prerequisite tasks (which may be empty) are given.
Find the minimal possible time required to complete all tasks. Output -1 if it is impossible to complete the project. All input numbers are positive integers not exceeding .
The first line contains the integer .
Each of the following lines describes a task: the execution time and the list of prerequisite tasks (if any).
Output a single number — the minimum time to complete all tasks, or -1 if it is impossible.
Example 1