import Control.Monad
import Data.List
import Data.Maybe

main :: IO ()
main = do
    n <- read <$> getLine
    as <- replicateM n ((read :: String -> Int) <$> getLine)
    putStrLn $
        maybe "-1"
              show
              (f as 2)
    where
    f :: [Int] -> Int -> Maybe Int
    f as i = let is = (+ 1) <$> elemIndices i as
                 ms = mapMaybe (f as) is
             in case ms of
                 [] -> Nothing
                 xs -> Just $ minimum xs
