import Control.Monad
import qualified Data.IntMap.Strict as IntMap

main = do
  n <- readLn
  as <- map read <$> replicateM n getLine
  print $ f n t 1 . mkd 0 $ as

mkd _ [] = IntMap.empty
mkd k (a:as) = IntMap.insert k a (mkd (k+1) as)
    
f _ -1 _ _ = -1
f n t 2 _ = n - t
f n t x d = f n (t-1) (d ! x) d