Card Shuffling

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Yuuka has a deck of nn cards labeled with 0,1,2,,(n1)0, 1, 2, \dots, (n - 1).

Initially, the cards are placed in the order p_1,p_2,,p_np\_1, p\_2, \dots, p\_n from top to bottom. In each round, if the top card is labeled with xx, Yuuka will place it xx cards downward, so it becomes the card number (x+1)(x + 1) in the deck, counting from 11. The relative order of other cards will not be changed.

How many rounds will pass until the card labeled with 00 comes to the top?

입력

The first line contains an integer nn (1n321 \leq n \leq 32).

The second line contains nn distinct integers p_1,p_2,,p_np\_1, p\_2, \dots, p\_n (0p_i<n0 \leq p\_i < n).

출력

Output an integer which denotes the number of rounds. If the card labeled with 00 never comes to the top, output "-1" instead.