The last battle

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

문제

Soon there will be a final battle between people and Martians. Spies of people found out that the Martians had nn soldiers left. It also turned out that people as well as the Martians had exactly nn fighters. 

According to the experience of past battles, people know that only one Martian with the number ii can defeat an ii-th person.

The commander decided to build in a line of people. Learning Martians plans, the commander found out that a man with ii-th position in the line will fight with Martian number a_ia\_i. People will win only if each of the fighters is guaranteed to win in their battle.

Firstly commander put the ii-th person on the ii-th position int the line. After that, he realized that he had little time before the battle, and that people can lose if the line is not rebuilt. In one second he can move a person from the last place to the beginning of the line, after this operation this fighter is in the first position, and the position number of each of the other fighters is increased by 11

Help him to find out the minimal time he can rebuild the line so that people will win.

입력

The first line contains an integer nn --- the number of fighters of each side (1n21051 \le n \le 2\cdot10^5).

The second line contains nn distinct integers a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n, where a_ia\_i is the number of the Martian with whom the person from the ii-th position in the line will fight (1a_in1 \le a\_i \le n, if iji \ne j, then a_ia_ja\_i \ne a\_j).

출력

Output a single number kk --- the minimum number of seconds for which the commander can rebuild the line so that people will win. If people can not defeat the Martians, print the number <<1-1>>.

힌트

In the first example, initially the fighters stand opposite each other in the following way:

Martians:14235 People:  12345 \begin{matrix} \text{Martians:}&1&4&2&3&5\\\ \text{People:}    &1&2&3&4&5\\\ \end{matrix}

People lose, as the Martians number 11 and 55 win their fights. After the first move, the line of the fighters changes to this line:

Martians:14235 People:  51234 \begin{matrix} \text{Martians:}&1&4&2&3&5\\\ \text{People:}    &5&1&2&3&4\\\ \end{matrix}

Now the Martians 22 and 33 win their battle, so commander need to move the last person to the beginning of the line again. After it, the line of the fighters becomes such that all people win their fight.

Martians:14235 People:  45123 \begin{matrix} \text{Martians:}&1&4&2&3&5\\\ \text{People:}    &4&5&1&2&3\\\ \end{matrix}