open Batteries

let main () =
  let n, s = Scanf.scanf "%d\n%s" (fun x y -> x, y) in
  let ans = ref 30001 in
  for i = 0 to n - 1 do
    let x = if i > 0 then String.slice ~first:0 ~last:i s else "" in
    let y = String.slice ~first:(i+1) ~last:n s in
    ans := min !ans (String.fold_left (fun acc elem -> if Char.equal 'W' elem then acc + 1 else acc) 0 x +
                     String.fold_left (fun acc elem -> if Char.equal 'E' elem then acc + 1 else acc) 0 y)
  done;
  Printf.printf "%d\n" !ans

let _ = main ()
