A tournament is a single-elimination competition among n players. In each match two players compete: the loser is knocked out and the winner stays in (every match is decisive, there are no draws). The tournament ends when exactly one player is left, the champion.
The organizing federation fixes the schedule one match at a time. First it chooses the two players of match 1. Once that result is known, it chooses the two players (from those still in the tournament) of match 2, then match 3, and so on until a single player remains.
So the champion depends not only on the players' skill but also on the schedule, that is, on luck. The federation knows this. During the training season it watched the athletes closely, and for some pairs of players the result of a direct match is already certain.
Using that information, the federation asks, for a chosen player x, whether it can arrange the schedule so that x only ever meets opponents it is sure to beat (this of course makes x win the whole tournament). If such a schedule exists, we say the tournament can be rigged for player x.
Write a program that determines how many players the tournament can be rigged for.
The first line contains an integer n (1≤n≤1000), the number of players. Players are numbered 1,2,…,n.
Each of the next n lines describes one player. The i-th of these lines lists the players who are certain to defeat player i in a direct match: it starts with an integer m (how many players are stronger than player i) followed by their m numbers. All numbers on a line are separated by single spaces.
Output a single integer: the number of players for whom the tournament can be rigged.