Unfortunately, the wizard trapped Jim with a magic called Maze, and then he went home prepered for the delicious cat-meet-dinner. He would come back at time T.
The magic Maze transmits somebody to a special square. At there, one must solve a riddle to get out, or waiting for powerful wizard to dispel the Maze.
On the square, there are N rows stone. Each row has M stones. Each stone has its own number, and there are M pieces of stone whose number is k(1<=k<=N). Only all the stone in kth row has the same number k, the person can exit the Maze.
Certainly, Jim didn’t want to become a cat-meet-dinner, so he asked you for help.
You can assume Jim would take 1 time from one row to any row (nomatter he took a stone or not), and when start (time 0), he could go to any row he likes.
Notice: even Jim can get out of magic Maze, he also need at least 1 time to call for help.(After that he would save by SuperCat and Wizard would lost his cat-meet-dinner. Clearly he might be crazy and do something terrible. For exmaple, he might summon some vampire to catch the cat Jim and then destroy the Happy Forest:( After all, he was a dread wizard.)
4 3 10 1 3 1 2 3 3 1 2 2 4 4 4 4 3 1 1 3 1 2 3 3 1 2 2 4 4 4
6 6 Poor Cat