import Control.Monad
import qualified Data.IntMap.Strict as IntMap
main = do
  n <- readLn
  as <- map read <$> replicateM n getLine
  let asd = mkd 0 as where
     mkd _ [] = IntMap.empty
     mkd k (a:as) = IntMap.insert k a (mkd (k+1) as)
  print $ f n t 1 mkd where
    f _ -1 _ _ = -1
    f n t 2 _ = n - t
    f n t x d = f n (t-1) (d ! x) d