module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = words
printer = unlines . (:[]) . show

solver [ns,ss] = leader_cost ss (int ns)
leader_cost ss n 
  | n == 1 = 0
  | n >= 2 = result
  where
    ln = div n 2
    rn = n - ln
    (ls,rs) = splitAt ln ss
    result = min (count 'W' ls + leader_cost rs rn)
                 (count 'E' rs + leader_cost ls ln)
    
count c = length . filter (==c)
