import Data.List       (foldl')

type Dice    = [(Int, Int)]
type Command = Char

fromList :: [Int] -> Dice
fromList [a, b, c, d, e, f] = [(a, f), (b, e), (c, d)]
fromList _ = error "Invalid dice."

rev :: (a,a) -> (a,a)
rev (x,y) = (y,x)

roll :: Dice -> Command -> Dice
roll [a, b, c] com =
    case com of
        'N' -> [b, rev a, c]
        'E' -> [rev c, b, a]
        'S' -> [rev b, a, c]
        'W' -> [c, b, rev a]
        _   -> error "Invalid command."
roll _ _ = error "Invalid command."

top :: Dice -> Int
top [(a,_),(_,_),(_,_)] = a
top _ = error "Invalid dice."

main :: IO ()
main = do
    dice <- (fromList . map read . words) <$> getLine
    print . top . foldl' roll dice =<< getLine