#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;


ll dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
ll counterb=0,counterw=0;
void dfs(ll x,ll y,ll H, ll W,vector<vector<bool>> &field,vector<vector<bool>> &check){
    check[x][y]=1;
    if(field[x][y]==1){counterb++;}
    if(field[x][y]==0){counterw++;}
    bool meter=(x+y+field[x][y])%2;
    for(int i=0;i<4;i++){if(x+dx[i]>=0&&x+dx[i]<H&&y+dy[i]>=0&&y+dy[i]<W){
        if(check[x+dx[i]][y+dy[i]]==0&&(x+y+dx[i]+dy[i]+field[x+dx[i]][y+dy[i]])%2==meter){
            dfs(x+dx[i],y+dy[i],H,W,field,check);
        };}
    ;}
    

}




int main(){
ll H;
cin >> H;
ll W;
cin >> W;
vector<vector<bool>> field(H, vector<bool>(W, 0));
vector<vector<bool>> check(H, vector<bool>(W, 0));
for(int i=0;i<H;i++){
 for(int j=0;j<W;j++){
     char k;
     cin>>k;
     if(k=='#'){field[i][j]=1;}
 ;}
;}
    ll ans=0;
for(ll i=0;i<H;i++){
 for(ll j=0;j<W;j++){
     
     if(check[i][j]==0){
         dfs(i,j,H,W,field,check);ans+=counterb*counterw;
         counterb=0;counterw=0;
     }
     
 ;}
;}
cout<<ans<<endl;
return 0;


}  


#include <bits/stdc++.h> 
 
using namespace std; 

int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
char board[401][401];
int h,w;
int visited[401][401];
long long int arr[160005][2];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> h >> w;

	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin >> board[i][j];
		}
	}

	memset(visited,-1,sizeof(visited));

	int cnt = 0;

	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(visited[i][j]==-1 && board[i][j]=='#')
			{
				queue <pair<int,int>> que;
				que.push(make_pair(i,j));
				visited[i][j] = cnt;
				while(!que.empty())
				{
					int y = que.front().first;
					int x = que.front().second;
					que.pop();

					for(int k=0;k<4;k++)
					{
						int ny = y + dy[k];
						int nx = x + dx[k];
						if(ny < 0 || ny >= h || nx < 0 || nx >= w)
						{
							continue;
						}
						if(visited[ny][nx]==-1 && board[ny][nx]!=board[y][x])
						{
							visited[ny][nx] = cnt;
							que.push(make_pair(ny,nx));
						}
					}
				}
				cnt++;
			}
		}
	}

	long long int res = 0;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(visited[i][j]==-1)
			{
				continue;
			}
			if(board[i][j]=='#')
			{
				arr[visited[i][j]][0]++;
			}
			else
			{
				arr[visited[i][j]][1]++;
			}
		}
	}

	for(int i=0;i<cnt;i++)
	{
		res += (arr[i][0]*arr[i][1]);
	}

	cout << res << '\n';

    return 0;
}