import Data.List(sort,group)
import Control.Monad(forM_)

main = do
  ns <- fmap (fmap (read :: String -> Int) . words) . lines <$> getContents
  let n = head $ head ns
  let ls = concat $ tail ns
  putStrLn $ solve n ls

solve :: Int -> [Int] -> String
solve n ls
  | notElem 2 ls = "-1"
  | otherwise = show $ getAns n 1 (head ls) vs
  where
    vs = zip [1 .. length ls] ls

getAns :: Int -> Int -> Int -> [(Int, Int)] -> Int
getAns n c v vs
  | c > n = -1
  | v == 2 = c
  | otherwise = getAns n (c + 1) (takeOne v vs) vs

takeOne :: Int -> [(Int, Int)] -> Int
takeOne x vs
  | l == [] = -1
  | otherwise = snd $ head $ sort $ l
  where
    l = filter (\t -> fst t == x) vs