#include <iostream>
#include <vector>
#include <string>
#include <utility>

using namespace std;
string s[500];
vector<int> G[200000];
bool used[200000];
long long a[200000],b[200000] = {},wh[200000] = {};
void dfs(int x){
	used[x] = true;
	for(int v:G[x]){
		if(!used[v]){
			a[v] = a[x];
			dfs(v);
		}
	}
}

int main(){
	int i,j,h,w,n;
	cin >> h >> w;
	n = h*w;
	for(i=0;i<h;i++){
		cin >> s[i];
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(j!=w-1 && s[i][j]!=s[i][j+1]){
				G[i*w+j].push_back(i*w+j+1);
				G[i*w+j+1].push_back(i*w+j);
			}
			if(i!=h-1 && s[i][j]!=s[i+1][j]){
				G[i*w+j].push_back((i+1)*w+j);
				G[(i+1)*w+j].push_back(i*w+j);
			}
		}
	}
	for(i=0;i<n;i++) used[i] = false;
	for(i=0;i<n;i++){
		if(!used[i]){
			a[i] = i;
			dfs(i);
		}
	}
	for(i=0;i<n;i++){
		if(s[i/w][i%w]=='#') b[a[i]]++;
		else wh[a[i]]++;
	}
	long long ans = 0;
	for(i=0;i<n;i++){
		ans += b[i]*wh[i];
	}
	cout << ans << endl;
}
		
	