
fun main(args:Array<String>):Unit {
    val (n, _) = readLine()!!.trim().split(' ').map(String::toInt)
    val state = Array(n){readLine()!!.trim().toCharArray()}
    val notWhite = state.map{it.count{it != 'W'}}.toIntArray()
    val notBlue = state.map{it.count{it != 'B'}}.toIntArray()
    val notRed = state.map{it.count{it != 'R'}}.toIntArray()
    for (i in 1 until n){
        notWhite[i] += notWhite[i - 1]
        notBlue[i] += notBlue[i - 1]
        notRed[i] += notRed[i - 1]
    }
    var min = Int.MAX_VALUE
    for (w in 0 until n - 2){
        for (b in w + 1 until n - 1){
            if (notRed.last() - notRed[b] + notBlue[b] - notBlue[w] + notWhite[w] < min){
                min = notRed.last() - notRed[b] + notBlue[b] - notBlue[w] + notWhite[w]
            }
        }
    }
    println(min)
}
