#include<iostream>
#include<bitset>
#include<string.h>
using namespace std;
typedef long long ll;
bool vis[401][401];
char mat[401][401];
int H,W;
ll blk, wht;
void dfs(int i, int j){
    vis[i][j] = true;
    int r[] = {1, -1, 0, 0}, c[] = {0, 0, 1, -1};
    int cnt = 0;
    if (mat[i][j] == '#') blk++;
    if (mat[i][j] == '.') wht++;
    for (int x=0;x<4;x++){
        int ni = i + r[x], nj = j + c[x];
        if (ni < H && ni >=0 && nj < W && nj >= 0 && !vis[ni][nj] && mat[ni][nj]!= mat[i][j])
            dfs(ni, nj);
    }
    // cout << "cnt: " << cnt << endl;
}   

int main(void){
    cin >> H >> W;
    for (int i=0;i<H;i++)
        cin >> mat[i];
    memset(vis,false,sizeof(vis));
    ll ans = 0;
    for (int i=0;i<H;i++){
        for (int j=0;j<W;j++){
            if (vis[i][j]) continue;
            blk = 0;
            wht = 0;
            dfs(i, j);
            ans += blk*wht;
        }
    }
    cout << ans << endl;
}