
module Main where

import Debug.Trace

main :: IO ()
main = do
  a <- map read . words <$> getLine
  --a `traceShow`
  print $ solve a


solve :: [Int] -> Int
solve s = check $ zip [1, 2, 3, 4, 5] s

check :: [(Int, Int)] -> Int
check [] = undefined
check ((a, 0):ps) = a
check (_:ps) = check ps
