import Control.Monad
import Control.Applicative

main :: IO ()
main = do
  getLine
  xs <- map read . words <$> getLine
  ops <- getLine
  let
    fu 'm' = min :: Integer -> Integer -> Integer
    fu 'M' = max
  print $ head $ foldl proc xs $ map fu ops

proc :: [a] -> (a -> a -> a) -> [a]
proc xs f = zipWith f xs $ tail xs