#include using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl #define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;} #define printP(p) cout << p.first << " " << p.second << endl #define printVP(vp) for(auto&& p : vp) printP(p); typedef long long ll; typedef pair Pii; typedef tuple TUPLE; typedef vector vi; typedef vector vvi; typedef vector vvvi; typedef vector vp; const int inf = 1e9; const int mod = 1e9 + 7; template using Graph = vector>; // N, E, S, W const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = { 0, 1, 0, -1}; int H, W; inline bool inside(int x, int y) { return 0 <= x && x < H && 0 <= y && y < W; } int node(int i, int j) { return i * W + j; } class BiMatch { private: const int n; vector> G; vector match; vector used; bool dfs(int v) { used[v] = true; for (const auto& u : G[v]) { int w = match[u]; if (w < 0 || !used[w] && dfs(w)) { match[v] = u; match[u] = v; return true; } } return false; } public: BiMatch(int _n) : n(_n), G(_n) {} void addEdge(int u, int v) { G[u].emplace_back(v); G[v].emplace_back(v); } int calc() { int res = 0; match.clear(); match.resize(n, -1); rep(v, n) { if (match[v] < 0) { used.clear(); used.resize(n, false); if (dfs(v)) { res++; } } } return res; } }; signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); cin >> H >> W; vector choco(H); rep(i, H) cin >> choco[i]; BiMatch bimatch(H * W); int nw = 0, nb = 0; rep(i, H) { rep(j, W) { if (choco[i][j] == 'w') { nw++; rep(k, 4) { int ni = i + dx[k], nj = j + dy[j]; if (inside(ni, nj) && choco[ni][nj] == 'b') { bimatch.addEdge(node(i, j), node(ni, nj)); } } } else if (choco[i][j] == 'b') { nb++; } } } int num_match = bimatch.calc(); int ans = 100 * num_match; cerr << ans << endl; nw -= num_match; nb -= num_match; ans += 10 * min(nb, nw); cerr << ans << endl; ans += max(nw - nb, nb - nw); cerr << ans << endl; cout << ans << endl; }