import java.util.Scanner; public class Y421 { int N, M; char[][] S; int[][] matchRow, matchCol; boolean[][] checked; Y421() { Scanner sc = new Scanner(System.in); N = sc.nextInt(); M = sc.nextInt(); S = new char[N][]; for (int i = 0; i < S.length; i++) { S[i] = sc.next().toCharArray(); } matchRow = new int[N][M]; matchCol = new int[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { matchRow[i][j] = -1; matchCol[i][j] = -1; } } int cnt = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (matchCol[i][j] == -1 && S[i][j] != '.') { checked = new boolean[N][M]; if (search(i, j)) { cnt++; } } } } int black = 0, white = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (matchCol[i][j] < 0) { if (S[i][j] == 'b') black++; if (S[i][j] == 'w') white++; } } } int happiness = cnt * 100 + 10 * Math.min(black, white) + Math.abs(black - white); System.out.println(happiness); } boolean search(int i, int j) { if (checked[i][j]) { return false; } checked[i][j] = true; int[] i_array = { i, i-1, i, i+1 }; int[] j_array = { j-1, j, j+1, j }; for (int i2 : i_array) { for (int j2 : j_array) { if (0 <= i2 && i2 < N && 0 <= j2 && j2 < M) { if (S[i2][j2] != '.' && S[i][j] != S[i2][j2]) { if (matchCol[i2][j2] < 0 || search(matchRow[i2][j2], matchCol[i2][j2])) { matchCol[i][j] = j2; matchRow[i][j] = i2; matchCol[i2][j2] = j; matchRow[i2][j2] = i; return true; } } } } } return false; } public static void main(String argv[]) { new Y421(); } }