import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.Char

data Dice = Dice [Int] deriving Show

rollDice :: Char -> Dice -> Dice
rollDice 'N' (Dice [a,b,c,d,e,f]) = Dice [b,f,c,d,a,e]
rollDice 'E' (Dice [a,b,c,d,e,f]) = Dice [d,b,a,f,e,c]
rollDice 'S' d = foldr1 (.) (replicate 3 $ rollDice 'N') $ d
rollDice 'W' d = foldr1 (.) (replicate 3 $ rollDice 'E') $ d

topDice :: Dice -> Int
topDice (Dice (a:_)) = a


main = do
  as <- map read . words <$> getLine
  getLine >>= return . topDice . foldl (flip rollDice) (Dice as) >>= print