#include char field[64][64]; int h, w; int dr[4] = {1, 0, -1, 0}; int dc[4] = {0, 1, 0, -1}; bool outOfRange(int r, int c) { if( not ( 0 <= r and r < h and 0 <= c and c < w ) ) return true; return false; } int main() { scanf("%d %d", &h, &w); for(int i = 0; i < h; ++i) { scanf("%s", field[i]); } int res = 0; bool updated = false; int w_count = 0, b_count = 0; do { updated = false; for(int r = 0; r < h; ++r) { for(int c = 0; c < w; ++c) { if( field[r][c] == '.' ) continue; int count = 0; int kk = -1; for(int k = 0; k < 4; ++k) { int nr = r + dr[k], nc = c + dc[k]; if( outOfRange(nr, nc) ) continue; if( field[nr][nc] == '.' ) continue; count += 1; kk = k; } if( count == 0 ) { switch( field[r][c] ) { case 'w' : w_count += 1; break; case 'b' : b_count += 1; break; } field[r][c] = '.'; updated = true; } if( count == 1 ) { field[r][c] = field[r+dr[kk]][c+dc[kk]] = '.'; res += 100; updated = true; } } } } while( updated ); int w2_count = 0, b2_count = 0; for(int r = 0; r < h; ++r) { for(int c = 0; c < w; ++c) { switch( field[r][c] ) { case 'w' : w2_count += 1; break; case 'b' : b2_count += 1; break; } } } res += 100 * std::min(w2_count, b2_count); w_count += w2_count - std::min(w2_count, b2_count); b_count += b2_count - std::min(w2_count, b2_count); res += 10 * std::min(w_count, b_count) + std::abs(w_count - b_count); printf("%d\n", res); return 0; }