/*
                    !!!!!!                                                     
                    !!!!!!!!!!                                                 
                     !!!!!!!!!!!!!!!                                           
                       !!!!!!!!!!!!!!                                          
                     !!!!!!!!!!!!!!!                                           
                      !!!!!!!!!!!!                                             
                      !!!!!!!!!!!!                                             
                        !!!!!!!!!!!!                                           
                        !!!!!!!!                                               
                        !!!!!!!!!!                                             
                       !!!!!!!!!!!!!!                                          
                     !!!!!!!!!!!!!!!!                                          
                    !!!!!!!!!!!!!!!!                                  !!!!!    
                  !!!!!!!!!!!!!!!!!!!                               !!!!!!!!!! 
                 !!!!!!!!!!!!!!!!!!!!!!!                 !         !!!!!!!!!!  
            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!              !!     !!!!!!!!!!!!    
           !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !!      !!!!!!!!       
            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!      
             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!       
              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  !!!!!!!!!!!!       
       !!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !!!!!!        
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!      !!!!!         
          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !!!          
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !          
          !!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                       
           !!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                         
                  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                          
                 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                           
                  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                               
                  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                               
                  !!!!!!!!!!!!!!!!!!!!!!!!!!!!                                 
                  !!!!!!!!!!!!!!!!!!!!!!!!!!                                   
                  !!!!!!!!!!!!!!!!!!!!!!!!!                                    
                   !!!!!!!!!!!!!!!!!!!!!!!!                                    
                    !!!!!!!!!!!!!!!!!!!!                                       
                    !!!!!!!!!!!!!!!!!!!                                        
                     !!!!!!!!!!!!!!!!                                          
                      !!!!!!!!!!!!!!!!                                         
                      !!!!!!!!!!!!!!!                                          
                       !!!!!!!!!!!!!!                                          
                        !!!!!!!!!!!!                                           
                        !!!!!!!!!!!!                                           
                        !!!!!!!!!!!!                                           
                          !!!!!!!!                                             
                          !!!!!!                                               
                           !!!! 
*/                                               
#include <bits/stdc++.h>
#define MAXN 500005
#define mod 1000000007
using namespace std;
/*
 *  author  :  vivekcrux
 */
typedef long long ll; 
typedef pair<ll,ll> pll;

ll power(ll x,ll y,ll m=mod)
{
	ll ans = 1;
	while(y>0)
	{
		if(y&1)
		{
			ans = (ans*x)%m;
		}
		x = (x*x)%m;	
		y /= 2;
	}
	return ans%m;
}

ll modInverse(ll a, ll m=mod) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        ll q = a / m; 
        ll t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 


int main()
{
// 	freopen("input.txt","r",stdin);

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n,i,j,k,m;
	cin>>n>>m;
	ll grid[n+1][m+1];
	string s[n+1];
	for(i=1;i<=n;i++)
	{
	    cin>>s[i];
	    for(j=1;j<=m;j++)
	    {
	        if(s[i][j-1] == '#') grid[i][j] = 1;
	        else    grid[i][j] = 0;
	        //cout<<grid[i][j]<<" ";
	    }//cout<<endl;
	}
	
	ll vis[n+1][m+1];
	memset(vis,0,sizeof(vis));
	ll ans = 0;
	for(i=1;i<=n;i++)
	{
	    for(j=1;j<=m;j++)
	    {
	        if(!vis[i][j])
	        {
	            ll cb=0,cw=0;
	            queue<pll> q;
	            q.push({i,j});
	            while(!q.empty())
	            {
	                pll tp = q.front();
	                q.pop();
	                ll x = tp.first, y = tp.second;
	                vis[x][y] = true;
	                if(grid[x][y]==1)   cb++;
	                else    cw++;
	               // cout<<x<<":"<<y<<":"<<grid[x][y]<<" ";
	                if(x+1<=n && grid[x+1][y]!=grid[x][y] && !vis[x+1][y])
	                {
	                    q.push({x+1,y});
	                    vis[x+1][y] = true;
 	                }
	                if(y+1<=m && grid[x][y+1]!=grid[x][y] && !vis[x][y+1])
	                {
	                    q.push({x,y+1});
	                    vis[x][y+1] = true;
 	                }if(x-1>0 && grid[x-1][y]!=grid[x][y] && !vis[x-1][y])
	                {
	                    q.push({x-1,y});
	                    vis[x-1][y] = true;
 	                }
	                if(y-1>0 && grid[x][y-1]!=grid[x][y] && !vis[x][y-1])
	                {
	                    q.push({x,y-1});
	                    vis[x][y-1] = true;
 	                }
	            }
	           // cout<<endl;
	           // cout<<i<<" "<<j<<" "<<cb<<" "<<cw<<endl;
	            ans += cb*cw;
	        }
	    }
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 2944