#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <algorithm>
using namespace std;

int H, W;

int main() {
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }
    vector<vector<int>> group(H, vector<int>(W));
    int g = 0;
    map<int, pair<int, int>> count;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (group[i][j] > 0) continue;
            
            //未訪問の頂点からDFS
            g++;
            stack<pair<int, int>> stack;
            stack.push(make_pair(i, j));
            if (S[i][j] == '.') {
                count[group[i][j]].first++;
            } else if (S[i][j] == '#') {
                count[group[i][j]].second++;
            }
            group[i][j] = g;
            if (S[i][j] == '.') {
                count[g].first++;
            } else if (S[i][j] == '#') {
                count[g].second++;
            }
            while (!stack.empty()) {
                pair<int, int> p = stack.top(); stack.pop();
                if (p.first > 0 && group[p.first - 1][p.second] == 0 && S[p.first - 1][p.second] != S[p.first][p.second]) {
                    group[p.first - 1][p.second] = g;
                    stack.push(make_pair(p.first - 1, p.second));
                    if (S[p.first - 1][p.second] == '.') {
                        count[g].first++;
                    } else if (S[p.first - 1][p.second] == '#') {
                        count[g].second++;
                    }
                }
                if (p.second > 0  && group[p.first][p.second - 1] == 0 && S[p.first][p.second - 1] != S[p.first][p.second]) {
                    group[p.first][p.second - 1] = g;
                    stack.push(make_pair(p.first, p.second - 1));
                    if (S[p.first][p.second - 1] == '.') {
                        count[g].first++;
                    } else if (S[p.first][p.second - 1] == '#') {
                        count[g].second++;
                    }
                }
                if (p.first < H - 1 && group[p.first + 1][p.second] == 0 && S[p.first + 1][p.second] != S[p.first][p.second]) {
                    group[p.first + 1][p.second] = g;
                    stack.push(make_pair(p.first + 1, p.second));
                    if (S[p.first + 1][p.second] == '.') {
                        count[g].first++;
                    } else if (S[p.first + 1][p.second] == '#') {
                        count[g].second++;
                    }
                }
                if (p.second < W - 1 && group[p.first][p.second + 1] == 0 && S[p.first][p.second + 1] != S[p.first][p.second]) {
                    group[p.first][p.second + 1] = g;
                    stack.push(make_pair(p.first, p.second + 1));
                    if (S[p.first][p.second + 1] == '.') {
                        count[g].first++;
                    } else if (S[p.first][p.second + 1] == '#') {
                        count[g].second++;
                    }
                }
            }
        }
    }
    long long ans = 0;
    for (int i = 1; i <= g; i++) {
        ans += 1ll * count[i].first * count[i].second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9728