import std.stdio;
import std.algorithm;
import std.range;
import std.array;
import std.conv;
import std.string;

long h, w;
string[] field;
long[][] used;

void dfs(long y, long x, char m, ref long a, ref long b) {
  if (field[y][x] == m) {
    a++;
  } else {
    b++;
  }
  used[y][x] = 1;

  if (y - 1 >= 0 && field[y][x] != field[y-1][x] && used[y-1][x] == 0) { 
    dfs(y - 1, x, m, a, b);
  }
  if (x - 1 >= 0 && field[y][x] != field[y][x-1] && used[y][x-1] == 0) {
    dfs(y, x - 1, m, a, b);
  }
  if (y + 1 < h && field[y][x] != field[y+1][x] && used[y+1][x] == 0) { 
    dfs(y + 1, x, m, a, b);
  }
  if (x + 1 < w && field[y][x] != field[y][x+1] && used[y][x+1] == 0) {
    dfs(y, x + 1, m, a, b);
  }

}


void main() {
  readf("%d %d\n", &h, &w);
  used = new long[][](h, w);

  foreach (_; 0..h) {
    field ~= readln.strip;
  }

  long r = 0;
  foreach (y; 0..h) {
    foreach (x; 0..w) {
      if (used[y][x] == 0) {
        long a, b;
        dfs(y, x, field[y][x], a, b);
        r += a * b;
      }
    }
  }
  writeln(r);
}
