

Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 点
問題文
筋力をつけたい高橋君は、AtCoder 社のトレーニング設備で、トレーニングをすることにしました。
AtCoder 社のトレーニング設備には 個のボタンがついており、ちょうど 個のボタンが光っています。 ボタンには、 から までの番号がついています。 ボタン が光っているときにそのボタンを押すと、ボタン の明かりが消え、その後ボタン が光ります。 であることもあります。 光っていないボタンを押しても、何も起こりません。
最初、ボタン が光っています。高橋君は、ボタン が光っている状態で、トレーニングをやめたいと思っています。
そのようなことは可能かどうか判定し、もし可能なら最低で何回ボタンを押す必要があるかを求めてください。
制約
入力
入力は以下の形式で標準入力から与えられる。
:
出力
ボタン を光らせることが不可能な場合、 を出力せよ。 そうでない場合、ボタン を光らせるために必要なボタンを押す回数の最小値を出力せよ。
入力例 1Copy
3 3 1 2
出力例 1Copy
2
ボタン の順に押せばよいです。
入力例 2Copy
4 3 4 1 2
出力例 2Copy
-1
ボタン を押すとボタン 、ボタン を押すとボタン が光るので、ボタン が光ることはありません。
入力例 3Copy
5 3 3 4 2 4
出力例 3Copy
3
Score : points
Problem Statement
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has buttons, and exactly one of the buttons is lighten up. These buttons are numbered through . When Button is lighten up and you press it, the light is turned off, and then Button will be lighten up. It is possible that . When Button is not lighten up, nothing will happen by pressing it.
Initially, Button is lighten up. Takahashi wants to quit pressing buttons when Button is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
Input
Input is given from Standard Input in the following format:
:
Output
Print if it is impossible to lighten up Button . Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button .
Sample Input 1Copy
3 3 1 2
Sample Output 1Copy
2
Press Button , then Button .
Sample Input 2Copy
4 3 4 1 2
Sample Output 2Copy
-1
Pressing Button lightens up Button , and vice versa, so Button will never be lighten up.
Sample Input 3Copy
5 3 3 4 2 4
Sample Output 3Copy
3