from scipy.sparse import csr_matrix from scipy.sparse.csgraph import maximum_bipartite_matching N, M = map(int, input().split()) S = [input() for _ in range(N)] def idx2int(n, m): return (n * M + m) // 2 white, black = [], [] for x in range(N): for y in range(x % 2, M, 2): if S[x][y] == 'w': for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)): if 0 <= x + dx < N and 0 <= y + dy < M and S[x + dx][y + dy] == 'b': white.append(idx2int(x, y)) black.append(idx2int(x + dx, y + dy)) w_count = sum(s.count('w') for s in S) b_count = sum(s.count('b') for s in S) matr = csr_matrix(([1] * len(white), (white, black)), shape=(N * M // 2, N * M // 2)) match = sum(maximum_bipartite_matching(matr, perm_type='column') != -1) w_count -= match b_count -= match major, minor = max(w_count, b_count), min(w_count, b_count) print(match * 100 + minor * 10 + major - minor)