main = do
  n <- readLn :: IO Int
  as <- map read . words <$> getLine :: IO [Int]  
  let (i,j) = foldl (\(a,b) (c,d) -> if c < d then (a,b) else if abs (c-d) < abs (a-b) then (c,d) else (a,b)) (0,200001) $ zip [1..] as
  print $ if search as then -1 else i-j

search :: [Int] -> Bool
search xs = null $ filter (>=0) $ zipWith (-) [1..] xs