object Main extends App {
	val input = io.Source.stdin.getLines.toIndexedSeq.tail.head
	val wi = input.zipWithIndex.filter(_._1 == 'W')

	val bits = new java.util.BitSet()
	wi.foreach(e => bits.set(e._2, true))

	val ret = (0 until input.length).foldLeft(Int.MaxValue) { (min, i) =>
		val l = bits.get(0, i).cardinality
		val r = input.length - i - bits.get(i, Int.MaxValue).cardinality
		Math.min(min, l + r)
	}
	println(ret)
}
