solveImpl :: [Int] -> Int -> Int -> Int
solveImpl arr now number
    | now == length arr   = number
    | tmpNumber == number = solveImpl arr (now+1) (number+1)
    | otherwise           = solveImpl arr (now+1) number
    where tmpNumber = arr !! now

solve :: [Int] -> Int
solve arr
    | ans == 1  = -1
    | otherwise = length arr - ans + 1
    where ans = solveImpl arr 0 1

main = do
    n <- getLine
    arr <- map read . words <$> getLine
    let ans = solve arr
    print ans
