#include #include using namespace atcoder; #ifdef LOCAL #include #define dbg(...) debug::dbg(#__VA_ARGS__, __VA_ARGS__) #define prt(...) debug::prt(#__VA_ARGS__, __VA_ARGS__) #else #define dbg(...) void(0) #define prt(...) void(0) #endif using namespace std; // #define int ll #define rep(i, a, b) for(int i=static_cast(a), i##_end__=static_cast(b); i < i##_end__; i++) #define rep_r(i, a, b) for(int i=static_cast(a), i##_end__=static_cast(b); i >= i##_end__; i--) #define fore(i, a) for(auto& i: a) #define forei(i, it, a) for(auto [i, it] = std::pair{0, std::begin(a)}; it != std::end(a); i++, it++) #define all(x) std::begin(x), std::end(x) using ll = long long; // __int128; using ull = unsigned long long; template using priority_queue_g = priority_queue, greater>; template int siz(const C& c) { return static_cast(c.size()); } template constexpr int siz(const T (&)[N]) { return static_cast(N); } template inline void fil(A& a, const V &v){ if constexpr(is_array_v) for(auto& s: a) fil(s, v); else a = v; }; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template constexpr T pow2(T x){ return x * x; } template constexpr T divceil(T x, S div) { return (x % div == 0) ? x / div : (x >= 0) ? (x / div) + 1 : -((-x) / div); } template constexpr T divfloor(T x, S div){ return (x % div == 0) ? x / div : (x >= 0) ? (x / div) : -((-x) / div) - 1; } template inline void oneline(T x){ bool f = true; for(auto i: x){ if(f) f = false; else cout << " "; cout << i; } cout << endl; } inline void yesno(bool x){ cout << (x ? "Yes" : "No") << endl; } constexpr long long INF = 1LL << 60; // 1.15e18 constexpr int MOD = (int)1e9 + 7; void _main() { int H, W; cin >> H >> W; vector G(H); fore(e, G) cin >> e; int S = H * W; int T = S + 1; int cnt = 0; mf_graph mf(T + 1); auto f = [&](int y, int x){ return y * W + x; }; int w = 0, b = 0; rep(y, 0, H) rep(x, 0, W){ if(G[y][x] == '.') continue; if(G[y][x] == 'b') b++; else w++; cnt++; auto id = f(y, x); if((y + x) % 2){ mf.add_edge(id, T, 1); } else{ mf.add_edge(S, id, 1); for(auto _d : vector>{{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}}){ auto cy = y + _d[0], cx = x + _d[1]; if(cy < 0 || H <= cy || cx < 0 || W <= cx) continue; if(G[cy][cx] != '.') mf.add_edge(id, f(cy, cx), 1); } } } auto maxflow = mf.flow(S, T); int ans = maxflow * 100 + (min(w, b) - maxflow) * 10 + abs(w - b); cout << ans << endl; } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); _main(); }