open Batteries

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

let _ = main ()
