#include using namespace std; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif #define rep(i,n) for(int i=0;i<(int)(n);i++) #define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define all(x) (x).begin(),(x).end() #define foreach(u,v) for(auto (u) : (v)) #define pb push_back #define mp make_pair #define mt make_tuple typedef long long ll; typedef pair pii; typedef vector vi; typedef vector vvi; typedef pair pll; typedef vector vl; const int inf = 1e9; const ll linf = 1LL<<60; const ll mod = 1e9 + 7; const double eps = 1e-9; /* */ struct edge{ int to, cap, rev; edge(int t, int c, int r) { to = t; cap = c; rev = r; } }; int n, m; string c[50]; vector g[2500]; bool used[2500]; void add_edge(int from, int to, int cap) { g[from].pb(edge(to, cap, g[to].size())); g[to].pb(edge(from, 0, g[from].size()-1)); } int dfs(int v, int t, int f) { if(v == t) return f; used[v] = true; for(auto& e : g[v]){ if(e.cap > 0 and !used[e.to]){ int d = dfs(e.to, t, min(f, e.cap)); if(d > 0){ e.cap -= d; g[e.to][e.rev].cap += d; return d; } } } return 0; } int maxflow(int s, int t) { int flow = 0; while(1){ fill(used, used+n*m, false); int f = dfs(s, t, inf); if(f == 0) return flow; flow += f; } } int main() { cin >> n >> m; rep(i, n) cin >> c[i]; int s = n * m; int t = s + 1; int nw = 0, nb = 0; rep(i, n) rep(j, m){ if(c[i][j] == 'w'){ add_edge(s, m*i+j, 1); nw++; }else if(c[i][j] == 'b'){ add_edge(m*i+j, t, 1); nb++; } } int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; rep(i, n) rep(j, m){ if(c[i][j] == 'w'){ rep(k, 4){ int nx = j + dx[k]; int ny = i + dy[k]; if(nx < 0 or m <= nx or ny < 0 or n <= ny) continue; if(c[ny][nx] == 'b'){ add_edge(m*i+j, m*ny+nx, 1); } } } } int max_f = maxflow(s, t); int ten = min(nw-=max_f, nb-=max_f); cout << 100*max_f+10*ten+(nw+nb-ten*2) << endl; return 0; }