import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


int root(int[] uf, int u) {
  return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));
}
bool connect(int[] uf, int u, int v) {
  u = uf.root(u);
  v = uf.root(v);
  if (u == v) return false;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
  return true;
}


int H, W;
string[] S;

void main() {
  try {
    for (; ; ) {
      H = readInt();
      W = readInt();
      S = new string[H];
      foreach (x; 0 .. H) {
        S[x] = readToken();
      }
      auto uf = new int[H * W];
      uf[] = -1;
      foreach (x; 0 .. H) foreach (y; 0 .. W) {
        if (x > 0 && S[x - 1][y] != S[x][y]) {
          uf.connect((x - 1) * W + y, x * W + y);
        }
        if (y > 0 && S[x][y - 1] != S[x][y]) {
          uf.connect(x * W + (y - 1), x * W + y);
        }
      }
      auto cnt = new int[][](H * W, 2);
      foreach (x; 0 .. H) foreach (y; 0 .. W) {
        ++cnt[uf.root(x * W + y)][(S[x][y] == '#') ? 1 : 0];
      }
      long ans;
      foreach (u; 0 .. H * W) {
        if (uf[u] < 0) {
          ans += 1L * cnt[u][0] * cnt[u][1];
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
