#include using namespace std; using ll = long long; using pll = pair; #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll INF = 1LL << 60; const ll MAX_N = 2e5; struct Dinic{ struct Edge{ ll to; ll cap; ll rev; }; vector> G; vector level; vector iter; ll N; Dinic(vector> &G_){ N = (ll)G_.size(); G.resize(N); level.resize(N); iter.resize(N); rep(from, N){ for(pll p : G_[from]){ ll to = p.fi; ll cap = p.se; G[from].pb((Edge){to, cap, (ll)G[to].size()}); G[to].pb((Edge){from, 0, (ll)G[from].size()-1}); } } } void bfs(ll s, vector> &H){ rep(i, N) level[i]=-1; queue Q; level[s] = 0; Q.push(s); while(!Q.empty()){ ll v = Q.front(); Q.pop(); for(ll i=0; i<(ll)H[v].size(); i++){ Edge &e = H[v][i]; if(e.cap > 0 && level[e.to] < 0){ level[e.to] = level[v] + 1; Q.push(e.to); } } } } ll dfs(ll v, ll t, ll f, vector> &H){ if(v == t) return f; for(ll &i=iter[v]; i<(ll)H[v].size(); i++){ Edge &e = H[v][i]; if(e.cap > 0 && level[v] < level[e.to]){ ll d = dfs(e.to, t, min(f, e.cap), H); if(d > 0){ e.cap -= d; H[e.to][e.rev].cap += d; return d; } } } return 0; } ll max_flow(ll s, ll t){ vector> H(N); rep(from, N) for(Edge e : G[from]) H[from].pb(e); ll flow = 0; for(;;){ bfs(s, H); if(level[t] < 0) return flow; rep(i, N) iter[i] = 0; ll f; while((f = dfs(s, t, INF, H)) > 0){ flow += f; } } } }; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll h, w; cin >> h >> w; vector> a(h, vector(w)); rep(i, h) rep(j, w) cin >> a[i][j]; ll n = 0, wn = 0, bn = 0; vector> alloc(h, vector(w, -1)); rep(i, h) rep(j, w) if((i+j)%2 == 0 && a[i][j] != '.') alloc[i][j]=n++; wn = n; rep(i, h) rep(j, w) if((i+j)%2 == 1 && a[i][j] != '.') alloc[i][j]=n++; bn = n - wn; vector> G(n+2); ll s = n; ll t = n+1; rep(i, h) rep(j, w){ if((i+j)%2 == 0 && alloc[i][j] != -1){ G[s].pb({alloc[i][j], 1}); } } ll di[4] = {0, 0, 1, -1}; ll dj[4] = {1, -1, 0, 0}; rep(i, h) rep(j, w){ if((i+j)%2 == 1) continue; if(alloc[i][j] == -1) continue; rep(k, 4){ ll next_i = i + di[k]; ll next_j = j + dj[k]; if(next_i < 0 || next_j < 0 || h <= next_i || w <= next_j) continue; if(alloc[next_i][next_j]==-1) continue; G[alloc[i][j]].pb({alloc[next_i][next_j], 1}); } } rep(i, h) rep(j, w){ if((i+j)%2 == 1 && alloc[i][j] != -1){ G[alloc[i][j]].pb({t, 1}); } } Dinic dinic(G); ll x, y, z; z = dinic.max_flow(s, t); y = min(wn-z, bn-z); x = n - 2*z - 2*y; cout << x + 10*y + 100*z << endl; }