fun main(args: Array<String>) {
    val memberCount: Int = readLine()!!.trim().toInt()
    val members: List<String> = readLine()!!.trim().map {it.toString()}.subList(0, memberCount)

    val wRuisekiwa: Array<Int> = Array(memberCount + 1) {0}
    val eRuisekiwa: Array<Int> = Array(memberCount + 1) {0}

    members.forEachIndexed {index, member ->
        if (member == "W") {
            wRuisekiwa[index + 1] = wRuisekiwa[index] + 1
            eRuisekiwa[index + 1] = eRuisekiwa[index]
        } else {
            wRuisekiwa[index + 1] = wRuisekiwa[index]
            eRuisekiwa[index + 1] = eRuisekiwa[index] + 1
        }
    }

    // println(wRuisekiwa.toList())
    // println(eRuisekiwa.toList())

    var minTurnMemberCount: Int = memberCount

    members.forEachIndexed { index, member ->
        val turnMemberCount: Int = wRuisekiwa[index] + (eRuisekiwa[memberCount] - eRuisekiwa[index + 1])

        if (turnMemberCount < minTurnMemberCount) {
            minTurnMemberCount = turnMemberCount
        }
    }

    println(minTurnMemberCount)

}