#include "bits/stdc++.h"
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P =pair<int,int>;

int main(){
    int h,w;
    cin >> h >> w;
    vector <vector <int>> m(h,vector <int>(w,0)),m3(h,vector <int>(w,0));
    vector <vector <int>>m2,m4;
    
    string s,s2;
    rep(i,h){
        cin >> s;
        rep(j,w){
            s2=s[j];
            if(s2=="#"){
                m[i][j]=1;
            }
        }

    }


    m2=m;
    m4=m3;

    //cout << m[1][0] << endl;
    //cout << m2[1][0] << endl;
    
    queue <vector <int>> q1,q2;
    vector <int> qq1,qq2;
    //int l;
    ll bb,ww;
    ll ans=0;
    rep(i,h){
        rep(j,w){
            if(m2[i][j]==1){
                //cout << 3 << endl;
                //m4=m3;
                ww=0;
                bb=0;
                q1.push({i,j});
                m4[i][j]=-1;
                m2[i][j]=-1;
                while(q1.size()!=0 or q2.size()!=0){
                    if(q1.size()!=0){
                        qq1=q1.front();
                        q1.pop();
                        ++bb;
                        //cout << qq1[0] << qq1[1] <<  "b" << endl;
                        
                        
                        if(qq1[0]>0){
                        if(qq1[0]>0 and m4[qq1[0]-1][qq1[1]]==0 and m2[qq1[0]-1][qq1[1]]==0){
                            q2.push({qq1[0]-1,qq1[1]});
                            m4[qq1[0]-1][qq1[1]]=-1;
                            m2[qq1[0]-1][qq1[1]]=-1;
                        }
                        }
                        if(qq1[0]<(h-1)){
                        if(qq1[0]<(h-1) and m4[qq1[0]+1][qq1[1]]==0 and m2[qq1[0]+1][qq1[1]]==0){
                            q2.push({qq1[0]+1,qq1[1]});
                            m4[qq1[0]+1][qq1[1]]=-1;
                            m2[qq1[0]+1][qq1[1]]=-1;
                        }
                        }
                        if(qq1[1]>0){
                        if(qq1[1]>0 and m4[qq1[0]][qq1[1]-1]==0 and m2[qq1[0]][qq1[1]-1]==0){
                            q2.push({qq1[0],qq1[1]-1});
                            m4[qq1[0]][qq1[1]-1]=-1;
                            m2[qq1[0]][qq1[1]-1]=-1;
                        }
                        }
                        if(qq1[1]<(w-1)){
                        if(qq1[1]<(w-1) and m4[qq1[0]][qq1[1]+1]==0 and m2[qq1[0]][qq1[1]+1]==0){
                            q2.push({qq1[0],qq1[1]+1});
                            m4[qq1[0]][qq1[1]+1]=-1;
                            m2[qq1[0]][qq1[1]+1]=-1;
                        }
                        }



                    }

                    if(q2.size()!=0){
                        qq2=q2.front();
                        q2.pop();
                        //cout << qq2[0] << qq2[1] <<  "w" << endl;
                        //cout << m2[qq2[0]+1][qq2[1]] << endl;
                        
                        ++ww;
                        
                        if(qq2[0]>0){
                        if(qq2[0]>0 and m4[qq2[0]-1][qq2[1]]==0 and m2[qq2[0]-1][qq2[1]]==1){
                            q1.push({qq2[0]-1,qq2[1]});
                            m4[qq2[0]-1][qq2[1]]=-1;
                            m2[qq2[0]-1][qq2[1]]=-1;
                        }
                        }
                        if(qq2[0]<(h-1)){
                        if(qq2[0]<(h-1) and m4[qq2[0]+1][qq2[1]]==0 and m2[qq2[0]+1][qq2[1]]==1){
                            q1.push({qq2[0]+1,qq2[1]});
                            m4[qq2[0]+1][qq2[1]]=-1;
                            m2[qq2[0]+1][qq2[1]]=-1;
                        }
                        }
                        if(qq2[1]>0){
                        if(qq2[1]>0 and m4[qq2[0]][qq2[1]-1]==0 and m2[qq2[0]][qq2[1]-1]==1){
                            q1.push({qq2[0],qq2[1]-1});
                            m4[qq2[0]][qq2[1]-1]=-1;
                            m2[qq2[0]][qq2[1]-1]=-1;
                        }
                        }
                        if(qq2[1]<(w-1)){
                        if(qq2[1]<(w-1) and m4[qq2[0]][qq2[1]+1]==0 and m2[qq2[0]][qq2[1]+1]==1){
                            q1.push({qq2[0],qq2[1]+1});
                            m4[qq2[0]][qq2[1]+1]=-1;
                            m2[qq2[0]][qq2[1]+1]=-1;
                        
                        }
                        }



                    }





                }
                //cout << bb <<" " << ww << endl;
                ans+=bb*ww;
            }
        }
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 6228