//#define _GLIBCXX_DEBUG #include #define rep(i, n) for(int i=0; i; using vs = vector; using vi = vector; using vvi = vector; template using PQ = priority_queue; template using PQG = priority_queue, greater >; const int INF = 0xccccccc; const ll LINF = 922337203685477580LL; template inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second;} template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second;} struct BM { int V; vector > G; vector match; vector used; BM(int n=0) : V(n), G(n), match(n, -1), used(n) {} inline void add(int u, int v) { G[u].emplace_back(v); G[v].emplace_back(u); } bool dfs(int v) { used[v] = true; for(int u:G[v]) { int w = match[u]; if(w < 0 or (!used[w] and dfs(w))) { match[v] = u; match[u] = v; return true; } } return false; } int bipartite_matching() { int res = 0; for(int v = 0; v < V; v++) { if(match[v] < 0) { for(int i = 0; i < v; i++) used[i] = 0; if(dfs(v)) res++; } } return res; } }; const int N = 55; //head int n, m; string s[N]; int cnt; int di[] = {0, 1, 0, -1}; int dj[] = {1, 0, -1, 0}; inline bool able(int i, int j) {return i >= 0 and j >= 0 and i < n and j < m;} inline int num(int i, int j) {return i*m+j;} int ans; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; BM bpm(n*m); rep(i, n) cin >> s[i]; rep(i, n) rep(j, m) if(s[i][j] != '.') { cnt++; rep(k, 4) { int ni = i + di[k]; int nj = j + dj[k]; if(able(ni, nj) and s[ni][nj] != '.') { bpm.add(num(i, j), num(ni, nj)); } } } ans += 100 * bpm.bipartite_matching(); rep(i, n) rep(j, m) if(s[i][j] != '.') { rep(k, n) rep(l, m) if(s[i][j] != s[k][l] and s[k][l] != '.' and P(i, j) < P(k, l)) { bpm.add(num(i, j), num(k, l)); } } ans += 8 * bpm.bipartite_matching() + cnt - ans/50; cout << ans << endl; }