import Control.Monad 
  
  push :: Int -> [Int] -> Int -> [Int] -> Bool
  push 0 _ _ ps = 2 `elem` ps                          
  push n bs b ps = let pushed = bs !! (b-1)
        in push (n-1) bs pushed (pushed:ps)
  
  main :: IO ()
  main = do
    n <- readLn :: IO Int
    bs <- replicateM n readLn :: IO [Int]                                               
    print $ push n bs (head bs) []                                                      
~                                                                                                                                                                          
~                                          