object Main extends App {
	//	require(func("WEEWW") == 1)
	//	require(func("WEWEWEEEWWWE") == 4)
	//	require(func("WWWWWEEE") == 3)
	//	require(func("WWWWW") == 0)
	//	require(func("EEEEE") == 0)
	//
	//	println((0 to 30).map(_ => 'E').mkString(""))
	//	val start = System.currentTimeMillis()
	//	require(func((0 to 30000000).map(_ => 'E').mkString("")) == 0)
	//	println("elapsed:" + (System.currentTimeMillis() - start))

	def func(input: String): Int = {
		val bits = new java.util.BitSet(400000)
		//				val wi = input.zipWithIndex.filter(_._1 == 'W')
		//				wi.foreach(e => bits.set(e._2, true))
		input.foldLeft(0) { (i, e) =>
			bits.set(i, e == 'W')
			i + 1
		}
		subbb(input.length, bits)
	}

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

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

	val sc = System.in
	while (sc.read != '\n') ()
	val bits = new java.util.BitSet(400000)
	val len = sc.available - 1
	(0 until len).foreach { i =>
		bits.set(i, sc.read == 'W')
	}
	println(subbb(len, bits))
}
