import collections import sys sys.setrecursionlimit(10 ** 6) input = sys.stdin.readline def dfs(v, left, right, used, g): if v in used: return False used.add(v) for u in g[v]: if right[u] == -1 or dfs(right[u], left, right, used, g): right[u] = v left[v] = u return True return False def max_bipartite_matching(n, m, g): res = 0 left = [-1] * n right = [-1] * m used = set() update = True while update: update = False for i in range(len(left)): if left[i] == -1 and dfs(i, left, right, used, g): update = True res += 1 if update: used = set() return res, left, right N, M = map(int, input().split()) g = [input() for _ in range(N)] w = b = 0 adj = collections.defaultdict(list) for i in range(N): w += g[i].count('w') b += g[i].count('b') for j in range(M): if (i + j) % 2 == 1: continue for dr, dc in [(1, 0), (-1, 0), (0, 1), (0, -1)]: r = i + dr c = j + dc if 0 <= r < N and 0 <= c < M: if sorted([g[i][j], g[r][c]]) == ['b', 'w']: p = i * M + j q = r * M + c adj[p].append(q) cnt, _, _ = max_bipartite_matching(N * M, N * M, adj) w -= cnt b -= cnt k = min(w, b) ans = cnt * 100 + k * 10 + (w - k) + (b - k) print(ans)