main :: IO()
main = getContents >>= putOut.show.solve.formatIn
  where putOut s | null s || last s == '\n' = putStr s
                 | otherwise                = putStrLn s
   
formatIn :: String -> ([Int], String)
formatIn = (\((x:_),(y:_)) -> (map read $words x, y)).splitAt 1.lines

solve :: ([Int], String) -> Int
solve (xs,ys) = xs !! (foldl label 1 ys -1) 

label 1 'E' =  4
label 1 'N' =  2
label 1 'S' =  5
label 1 'W' =  3

label 2 'E' =  4
label 2 'N' =  1
label 2 'S' =  6
label 2 'W' =  3

label 3 'E' =  1
label 3 'N' =  2
label 3 'S' =  5
label 3 'W' =  6

label 4 'E' =  6
label 4 'N' =  2
label 4 'S' =  5
label 4 'W' =  1

label 5 'E' =  4
label 5 'N' =  1
label 5 'S' =  6
label 5 'W' =  3

label 6 'E' =  4
label 6 'N' =  5
label 6 'S' =  2
label 6 'W' =  3