let () = Scanf.scanf "%d\n%s\n" @@ fun n s ->
  let west = Array.make n 0 in
  let east = Array.make n 0 in
  for i = 0 to n - 1 do
    if s.[i] = 'W' then
      west.(i) <- 1
    else 
      east.(i) <- 1
  done;
  for i = 1 to n - 1 do
    west.(i) <- west.(i) + west.(i - 1)
  done;
  for i = n - 2 downto 0 do
    east.(i) <- east.(i) + east.(i + 1)
  done;
  Array.init (String.length s - 1) (fun i -> west.(i) + east.(i) - 1)
  |> Array.fold_left min max_int
  |> Printf.printf "%d\n"