import Data.IntMap as M
import Control.Monad.Trans.State
import Control.Monad

type CMap = M.IntMap Char
newtype Sta = Sta CMap CMap Int String

main = do
  getLine
  s <- getLine
  let initialSta = Sta initialMap (count s) 0 s
  print $ evalState solve initialSta

solve :: State Sta Int
solve = do
  Sta w e p s <- get
  when (null s) return p
  let 
    (c:cs) = s
    w' = M.adjust succ c w
    e' = M.adjust pred c w
    p' = w' M.! 'W' + e' M.! 'E'
  put $ Sta w' e' (min p p') cs

count :: String -> CMap
count = M.foldr (M.adjust succ) initialMap

initialMap :: CMap
initialMap = M.fromList [('E', 0), ('W', 0)]