n, m = gets.chomp.split.map(&:to_i)
arr = []
n.times{
    line = gets.chomp
    w = line.count("W")
    b = line.count("B")
    r = line.count("R")
    arr << [m - w, m - b, m - r]
}
min = nil
for i in 0..n-3
    for j in i+1..n-2
        sum = 0
        for k in 1..n-2
            if k <= i
                sum += arr[k][0]
            elsif k <= j
                sum += arr[k][1]
            else
                sum += arr[k][2]
            end
        end
        min = sum if min.nil? || min > sum
    end
end
puts arr[0][0] + min + arr[n-1][2]
