let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m 
       then upper_bound m r p
       else upper_bound l m p

(*
 * 西=左 
 * 東=右
 *)

let () = Scanf.scanf "%d\n%s\n" @@ fun n s ->
  let west, east =
    Array.init (String.length s) (fun i -> i)
      |> Array.to_list
      |> List.partition (fun i -> s.[i] = 'W')
  in
  let west = Array.of_list west
  in
  let east = Array.of_list east
  in
  Array.init (String.length s - 2) (fun i ->
    (* iより左にあり，左を向いているものの数 *)
    1 +
    upper_bound 0 (Array.length west) (fun j -> west.(j) < i + 1) +
    upper_bound 0 (Array.length east) (fun j -> i < east.(Array.length east - 1 - j)))
  |> Array.fold_left min (min (Array.length west) (Array.length east))
  |> Printf.printf "%d\n"