
lefteater::Int->[Char]->[Int]
lefteater n [] = []
lefteater n (x:xs) =n:(lefteater (if x=='W' then (n+1) else n) xs)

righteater::Int->[Char]->[Int]
righteater n [] = []
righteater n (x:xs) = n:(righteater (if x=='E' then (n+1) else n) xs)

solver::String -> Int
solver st = let st_r = reverse st in
            let left_score = lefteater 0 st in
            let right_score = reverse (righteater 0 st_r) in
            minimum (map (\(x,y)->x+y) (zip left_score right_score))

main::IO ()
main=do
  _<-getLine
  st<-getLine
  print (solver st)