h, w = gets.split.map(&:to_i)
a = (1..h).map { gets.chomp }
count = -> i, j, c {
    (i..j).map {|k| w - a[k].count(c)}.inject(:+)
}
p (1..h-1).to_a.combination(2).map {|b, r|
    count[0, b-1, ?W] + count[b, r-1, ?B] + count[r, h-1, ?R]
}.min
