Puzzle
On the planet Olympia, there's a popular puzzle involving stacks of multicolored cards. Imagine N stacks of cards arranged in a row on a table. In a single move, you can remove the top cards of the same color from any number of consecutive stacks.
Your task is to write a program that determines the minimum number of moves needed to clear all the cards from the table.
Input
The first line contains the number of stacks N (N ≥ 2). Each of the following N lines describes a stack: the line starts with the number of cards K (K ≥ 1) in that stack, followed by K natural numbers indicating the colors of the cards in the stack, listed from the bottom to the top. It is guaranteed that 1 ≤ N·K ≤ 10000.
Output
Output the minimum number of moves T required to remove all the cards.