#include using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define elif else if #define sp(x) fixed << setprecision(x) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() using ll = long long; using ld = long double; using pii = pair; using pil = pair; using pli = pair; using pll = pair; const ll MOD = 1e9+7; //const ll MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; const ld EPS = 1e-10; template bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; template struct Max_Flow{ struct edge{ int to; T cap; int rev; edge(int to, T cap, int rev) : to(to), cap(cap), rev(rev) {} }; vector> es; vector used; const T INF_T; Max_Flow(int n) : INF_T(numeric_limits::max()){ es.resize(n), used.resize(n); } void add_edge(int from, int to, T cap, bool directed = true){ es[from].eb(to, cap, sz(es[to])); es[to].eb(from, directed? 0 : cap, sz(es[from])-1); } T dfs(int now, int t, T flow){ if(now == t) return flow; used[now] = true; for(auto &e: es[now]){ if(!used[e.to] && e.cap > 0){ T f = dfs(e.to, t, min(flow, e.cap)); if(f > 0){ e.cap -= f; es[e.to][e.rev].cap += f; return f; } } } return 0; } T max_flow(int s, int t){ T flow = 0; for(;;){ fill(all(used), false); T f = dfs(s, t, INF_T); if(f == 0) return flow; flow += f; } } }; int main(){ int H, W; cin >> H >> W; int N = H*W; string S[H]; rep(i, H) cin >> S[i]; Max_Flow G(2*N+2); int s = 2*N, t = 2*N+1; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; int b = 0, w = 0; rep(i, H){ rep(j, W){ if(S[i][j] == '.') continue; if(S[i][j] == 'b'){ b++; G.add_edge(s, W*i+j, 1); rep(k, 4){ int ni = i+dx[k], nj = j+dy[k]; if(ni < 0 || ni >= H || nj < 0 || nj >= W) continue; G.add_edge(W*i+j, N+W*ni+nj, 1); } } else{ w++; G.add_edge(N+W*i+j, t, 1); } } } int f = G.max_flow(s, t); if(b < w) swap(b, w); int ans = 100*f + 10*(w-f) + 1*(b-w); cout << ans << endl; }