import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from math import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 class HopcroftKarp: def __init__(self, N0, N1): self.N0 = N0 self.N1 = N1 self.N = N = 2+N0+N1 self.G = [[] for i in range(N)] for i in range(N0): forward = [2+i, 1, None] forward[2] = backward = [0, 0, forward] self.G[0].append(forward) self.G[2+i].append(backward) self.backwards = bs = [] for i in range(N1): forward = [1, 1, None] forward[2] = backward = [2+N0+i, 0, forward] bs.append(backward) self.G[2+N0+i].append(forward) self.G[1].append(backward) def add_edge(self, fr, to): #assert 0 <= fr < self.N0 #assert 0 <= to < self.N1 v0 = 2 + fr v1 = 2 + self.N0 + to forward = [v1, 1, None] forward[2] = backward = [v0, 0, forward] self.G[v0].append(forward) self.G[v1].append(backward) def bfs(self): G = self.G level = [None]*self.N deq = deque([0]) level[0] = 0 while deq: v = deq.popleft() lv = level[v] + 1 for w, cap, _ in G[v]: if cap and level[w] is None: level[w] = lv deq.append(w) self.level = level return level[1] is not None def dfs(self, v, t): if v == t: return 1 level = self.level for e in self.it[v]: w, cap, rev = e if cap and level[v] < level[w] and self.dfs(w, t): e[1] = 0 rev[1] = 1 return 1 return 0 def flow(self): flow = 0 G = self.G bfs = self.bfs; dfs = self.dfs while bfs(): *self.it, = map(iter, G) while dfs(0, 1): flow += 1 return flow def matching(self): return [cap for _, cap, _ in self.backwards] H, W = MAP() S = [input() for _ in range(H)] U = H*W hk = HopcroftKarp(U, U) dx = [0, -1, 0, 1] dy = [1, 0, -1, 0] nb = 0 nw = 0 for i in range(H): for j in range(W): if S[i][j] == "b": nb += 1 elif S[i][j] == "w": nw += 1 if (i+j)%2 == 0 and S[i][j] == "w": for k in range(4): ny = i+dy[k] nx = j+dx[k] if 0 <= ny <= H-1 and 0 <= nx <= W-1 and S[ny][nx] == "b": hk.add_edge(i*W+j, ny*W+nx) ans = 0 f = hk.flow() ans += 100*f nb, nw = nb-f, nw-f m = min(nb, nw) ans += 10*m nb, nw = nb-m, nw-m ans += max(nb, nw) print(ans)