#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define int long long
using namespace std;

int h, w;
int W, B;
bool a[400][400];//使ったか？
string b[400];
int dx[4] = { -1,0,0,1 }, dy[4] = { 0,-1,1,0 };
void saiki(int x, int y) {
	if (a[x][y])return;
	a[x][y] = true;
	if (b[x][y] == '#')B++;
	else W++;
	for (int i = 0; i < 4; i++) {
		if (x + dx[i] < h&&x + dx[i] >= 0 && y + dy[i] < w&&y + dy[i] >= 0 && b[x + dx[i]][y + dy[i]] != b[x][y]) {
			saiki(x + dx[i], y + dy[i]);
		}
	}
}
signed main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++)cin >> b[i];
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			W = B = 0;
			saiki(i, j);
			ans += B*W;
		}
	}
	cout << ans << endl;
}
