fun c98(args: Array<String>) {
    class SegTree(n: Int) {
        var size: Int = 0
        var tree: Array<Int> = emptyArray()

        init {
            var curr = 1
            while (curr < n) {
                curr *= 2
            }
            size = curr
            tree = Array(2 * size - 1) { 0 }
        }

        fun update(index: Int, value: Int) {
            var curr = index + (size - 1)
            tree[curr] += value
            while (curr != (curr - 1) / 2) {
                curr = (curr - 1) / 2
                tree[curr] += value
            }
        }

        fun sumOfW(fromInclusive: Int, toInclusive: Int): Int {
            fun sum(myIndex: Int, myFromInclusive: Int, myToInclusive: Int): Int {
                if (myFromInclusive > toInclusive || myToInclusive < fromInclusive) {
                    return 0
                }
                if (myFromInclusive >= fromInclusive && myToInclusive <= toInclusive) {
                    return tree[myIndex]
                }
                val left = sum(myIndex * 2 + 1, myFromInclusive, ((myFromInclusive + myToInclusive + 1) / 2) - 1)
                val right = sum(myIndex * 2 + 2, ((myFromInclusive + myToInclusive + 1) / 2), myToInclusive)
                return left + right
            }
            return sum(0, 0, size - 1)
        }

        fun sumOfE(fromInclusive: Int, toInclusive: Int): Int {
            return toInclusive + 1 - fromInclusive - sumOfW(fromInclusive, toInclusive)
        }
    }

    val num = args[0].toInt()
    val people = args[1]

    val segTree = SegTree(num)
    people.toCharArray().forEachIndexed { index, c ->
        if (c == 'W') {
            segTree.update(index, 1)
        }
    }

    var ans = Int.MAX_VALUE
    (0..num - 1).map {
        val left = if (it == 0) 0 else segTree.sumOfW(0, it - 1)
        val right = if (it == num - 1) 0 else segTree.sumOfE(it + 1, num - 1)
        if (ans > left + right) {
            ans = left + right
        }
    }

    println(ans)
}

fun main(args: Array<String>) {
    c98(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}