open Batteries

let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let s = Scanf.scanf "%s " (fun a -> a) in

  let char_arr = Array.of_list (String.to_list s) in
  let res = ref n in

  let left_w = Array.make n 0 in
  let right_e = Array.make n 0 in

  for i=1 to (n-1) do
    if char_arr.(i-1) = 'W' then 
      left_w.(i) <- left_w.(i-1) + 1
    else
      left_w.(i) <- left_w.(i-1)
  done;

  for i=1 to (n-1) do
    let i = n-1-i in
    if char_arr.(i+1) = 'E' then 
      right_e.(i) <- right_e.(i+1) + 1
    else
      right_e.(i) <- right_e.(i+1)
  done;

  for i=0 to (n-1) do
    let v = left_w.(i) + right_e.(i) in
    if v < !res then res := v
  done;

  print_endline (string_of_int (!res))
