'use strict'

function main(s) {

  const lines  = s.split('\n')[1].split('');
  const points = [];

  let count = 0;
  for (let i = 0; i < lines.length; i++) {
    if (lines[i] === 'W') {
      count += 1;
    } else {
      count -= 1;
    }
    points.push(count);
  }

  const index = points.indexOf(Math.min(...points));
  const left  = lines.slice(0, index).filter(p => p === 'W').length;
  const right = lines.slice(index + 1).filter(p => p === 'E').length;
  const result = left + right;

  console.log(result);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
