Complete graph - 2#5338

Complete graph - 2

1 segundo
128 megabytes
Fácil

While discussing the personal lives of various villains, we have neglected Count Dooku. In his spare time, Count Dooku enjoys folding origami. He has organized his knowledge of origami as follows: Count Dooku knows figures, and for some of them, he knows how to obtain one from another with a single fold.

To help beginners, Dooku has developed a special table. The cell of the table contains "1" if Count Dooku can obtain figure from figure with a single fold, and "0" otherwise.

Initially, Count Dooku holds a clean sheet of paper, which is figure number according to his system, and he wants to create a crane—figure number .

Find the minimum number of folds required for Count Dooku to obtain the desired figure.

Entrada

The first line contains the integer (1 \leq n \leq 1000). The next lines contain Dooku's table, each as a string of characters ("0" or "1"). The (n+1)-th line contains integers and .

Salida

Print the minimum number of folds required for Count Dooku to make the desired figure. If it is impossible, print "-1".

prb5338.gif

Ejemplos

Ejemplo 1

Loading
Loading