#include #include using namespace std; using namespace atcoder; // using mint = modint1000000007; // const int mod = 1000000007; // using mint = modint998244353; // const int mod = 998244353; // const int INF = 1e9; // const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, l, r) for (int i = (l); i < (r); ++i) #define rrep(i, n) for (int i = (n)-1; i >= 0; --i) #define rrep2(i, l, r) for (int i = (r)-1; i >= (l); --i) #define all(x) (x).begin(), (x).end() #define allR(x) (x).rbegin(), (x).rend() #define P pair template inline bool chmax(A &a, const B &b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A &a, const B &b) { if (a > b) { a = b; return true; } return false; } const int dx[8] = { 0,1,0,-1,1,1,-1,-1 }; const int dy[8] = { 1,0,-1,0,1,-1,1,-1 }; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int h, w; cin >> h >> w; vectors(h); rep(i, h)cin >> s[i]; int st = h * w; int ed = st + 1; mf_graph mf(ed + 1); int l = 0, r = 0; rep(i, h)rep(j, w) { if (s[i][j] == 'w')mf.add_edge(st, i*w + j, 1), l++; else if (s[i][j] == 'b')mf.add_edge(i*w + j, ed, 1), r++; } rep(i, h)rep(j, w) { if (s[i][j] != 'w')continue; rep(t, 4) { int ni = i + dx[t]; int nj = j + dy[t]; if (ni < 0 || ni >= h)continue; if (nj < 0 || nj >= w)continue; if (s[ni][nj] != 'b')continue; mf.add_edge(i * w + j, ni*w + nj, 1); } } int e = mf.flow(st, ed); int e2 = min(l, r) - e; int e3 = l + r - e * 2 - e2 * 2; long long ans = e * 100 + e2 * 10 + e3; cout << ans << endl; return 0; }