#include using namespace std; class bipartite_matching { int n; vector > g; vector match; vector used; bool dfs(int v) { used[v] = true; for (int 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: bipartite_matching(int n) { this->n = n; this->g = vector >(n); this->match = vector(n, -1); this->used = vector(n); } void add_edge(int u, int v) { g[u].push_back(v); g[v].push_back(u); } int build() { int ret = 0; for (int v = 0; v < n; v++) { if (match[v] < 0) { fill(used.begin(), used.end(), false); if (dfs(v)) ++ret; } } return ret; } int pair(int v) { return match[v]; } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int r, c; cin >> r >> c; vector bd(r); for (int i = 0; i < r; i++) cin >> bd[i]; int black = 0; int white = 0; bipartite_matching matcher(r * c); for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { if (bd[i][j] == '.') continue; else if (bd[i][j] == 'w') ++white; else ++black; if (j + 1 < c && bd[i][j+1] != '.') matcher.add_edge(i * c + j, i * c + j + 1); if (i + 1 < r && bd[i+1][j] != '.') matcher.add_edge(i * c + j, (i + 1) * c + j); } } int matched = matcher.build(); int ret = 100 * matched; white -= matched; black -= matched; ret += 10 * min(white, black); ret += max(white, black) - min(white, black); cout << ret << endl; return 0; }