#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll h,w,cb=0,cw=0,ans=0;
char s[410][410];
bool b[410][410];

void search_area(int i,int j){
    b[i][j]=true;
    if(s[i][j]=='#') cb ++;
    if(s[i][j]=='.') cw ++;
    if(j<w-1&&s[i][j]!=s[i][j+1]&&!b[i][j+1]) search_area(i,j+1);
    if(j>0&&s[i][j]!=s[i][j-1]&&!b[i][j-1]) search_area(i,j-1);
    if(i<h-1&&s[i][j]!=s[i+1][j]&&!b[i+1][j]) search_area(i+1,j);
    if(i>0&&s[i][j]!=s[i-1][j]&&!b[i-1][j]) search_area(i-1,j);
    return;
}

int main(){
    cin >> h >> w;
    for(int i = 0;i < h;i ++){
        for(int j = 0;j < w;j ++){
            cin >> s[i][j];
        }
    }
    for(int i = 0;i < h;i ++){
        for(int j = 0;j < w;j ++){
            cb=0;
            cw=0;
            if(!b[i][j]){
                search_area(i,j);
                ans += cb*cw;
            }
        }
    }
    cout << ans << endl;
    return 0;
}