Skiers

No attempts yetTime limit1sMemory limit128 MB

Problem

On the southern slope of a mountain there are several ski tracks and a single ski lift. Every track runs from the top station of the lift down to the bottom station. Each morning a team of lift workers inspects the tracks: they ride the lift up together to the top station, and then each worker skis down to the bottom station along a track of their own choosing. Every worker skis down exactly once. Different workers' routes may share sections. Every route always leads downwards.

The ski area is a network of clearings joined by cuttings through the forest. Every clearing sits at a distinct height, and any two clearings are joined by at most one cutting. Skiing from the top to the bottom, a worker can pass through any clearing (though not necessarily all of them in a single run). Routes meet only at clearings; there are no tunnels or bridges.

A cutting is inspected when at least one worker skis along it. The workers want to inspect every cutting between the clearings using as few workers as possible.

Write a program that reads the map of ski tracks and computes the minimum number of workers whose routes together cover every cutting.

Input

The first line contains one integer nn, the number of clearings (2n50002 \le n \le 5000). The clearings are numbered from 11 to nn: clearing 11 is the top station of the lift and clearing nn is the bottom station.

Each of the next n1n-1 lines describes the downward cuttings leaving one clearing. Line i+1i+1 (for ii from 11 to n1n-1) describes clearing ii: it begins with an integer kk, the number of cuttings that lead down from clearing ii, followed by the numbers of the kk clearings they lead to, listed from west to east in the order the cuttings are arranged.

Output

Output a single integer: the minimum number of workers whose routes together inspect every cutting in the forest.