import Data.List

opposite :: Char -> Char
opposite d
    | d == 'U' = 'D'
    | d == 'D' = 'U'
    | d == 'N' = 'S'
    | d == 'S' = 'N'
    | d == 'E' = 'W'
    | d == 'W' = 'E'

turn :: Char -> Char -> Char
turn 'U' d = d
turn 'D' d = opposite d
turn f d
    | f == d          = 'D'
    | f == opposite d = 'U'
    | otherwise       = f

roll :: [(Int, Char)] -> Char -> [(Int, Char)]
roll fs d = map (\t -> (fst t, turn (snd t) d)) fs

solve :: String -> String -> String
solve f d = show $ fst $ (filter (\t -> snd t == 'U') $ foldl (\a c -> roll a c) fs d) !! 0
    where
        fs = zip (map read $ words f) "USEWND"

main :: IO ()
main = do
    f <- getLine
    d <- getLine
    putStrLn $ solve f d