fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val wcs = (0..(n - 1)).toMutableList()

    s.forEachIndexed { index, c ->
        wcs[index] = if (index == 0) 0 else wcs[index - 1]
        if (c == 'W') {
            wcs[index]++
        }
    }

    val min = (0..(n - 1)).map {
        val w = if (it == 0) 0 else wcs[it - 1]
        val e = n - (it + 1) - (wcs.last() - wcs[it])
        w + e
    }.min()

    println(min)
}