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

solve :: [Int] -> String
solve ls
  | notElem 2 ls = "-1"
  | otherwise = show $ length $ takeWhile (/=2) ls