import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Data.Array
main=print.solve.map(fst.fromJust.B.readInt).B.words=<<B.getContents
solve(n:xs)=jst.lookup 2$f n as 1 1 where as=listArray(1,n)xs
f n as c i|c>n=[]
f n as c i=(i',c):f n as(c+1)i' where i'=as!i
jst(Just i)=i
jst_= -1