#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
int main(void){
    ll h,w;
    cin>>h>>w;
    string s[h];
    rep(0,i,h)cin>>s[i];
    ll ans=0;
    vector<vector<bool>>d(h,vector<bool>(w,false));
    rep(0,i,h){
        rep(0,j,w){
            if(d[i][j]==false){
                ll cw=0,cb=0;
                queue<pair<ll,ll>>q;
                d[i][j]=true;
                q.push({i,j});
                while(!q.empty()){
                    ll x=q.front().first,y=q.front().second;q.pop();
                    if(s[x][y]=='#')++cb;
                    else ++cw;
                    rep(0,k,4){
                        ll nx=x+dx[k],ny=y+dy[k];
                        if(!(nx>=0&&nx<h&&ny>=0&&ny<w))continue;
                        if(s[x][y]!=s[nx][ny]&&(!d[nx][ny])){
                            d[nx][ny]=true;
                            q.push({nx,ny});
                        }
                    }
                }
                //cout<<cb<<" "<<cw<<endl;
                ans+=cw*cb;
            }
        }
    }
    cout<<ans;
}
#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;


}  

