#include <iostream>
using namespace std;
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using ll = long long;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
char c[405][405];
bool seen[400][400];
int h, w;
ll dfs(const int &i, const int &j, ll &ca, ll &cb) {
	if (seen[i][j]) return 0;
	seen[i][j] = 1;
	if (c[i][j] == '#')
		ca++;
	else
		cb++;
	rep(k, 4) {
		int nx = i + dx[k], ny = j + dy[k];
		if (nx < 0 or h <= nx or ny < 0 or w <= ny) continue;
		if (c[i][j] != c[nx][ny]) dfs(nx, ny, ca, cb);
	}
	return ca * cb;
}
int main() {
	scanf("%d%d", &h, &w);
	rep(i, h) scanf("%s", c[i]);
	ll ans = 0;
	rep(i, h) rep(j, w) {
		ll ca = 0, cb = 0;
		ans += dfs(i, j, ca, cb);
	}
	cout << ans << endl;
	return 0;
}
