CD exchange#121

CD exchange

1 second
64 megabytes
Easy

In a computer club, a CD exchange operates, allowing you to trade any disc for another from the catalog, either directly or through a series of exchanges. The catalog contains distinct discs, numbered from to . For each disc (i = 1 \ldots N), the catalog lists the discs that can be obtained by exchanging disc . Each exchange costs currency unit.

Input

The first line contains the integers and .

The next lines, for each disc , list the discs that can be obtained by exchanging disc .

Output

Output the minimum total amount required to obtain all discs from the catalog through exchanges.

All numbers are natural and do not exceed .

Examples

Example 1

Loading
Loading