object Main extends App {
//	require(func("WEEWW") == 1)
//	require(func("WEWEWEEEWWWE") == 4)
//	require(func("WWWWWEEE") == 3)
//	require(func((0 to 30000).map(_=>'W').mkString("")) == 0)

	def func(input: String): Int = {
		val wi = input.zipWithIndex.filter(_._1 == 'W')

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

		def count(s: Int, e: Int): Int = {
			//bits.get(s, e).cardinality
			(s until e).count(bits.get(_))
			//(s to e).foldLeft(0)((a, i) => if (bits.get(i)) a + 1 else a)
		}

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

	println(func(io.Source.stdin.getLines.toIndexedSeq.tail.head))
}
