/**
 * File              : C - Alternating Path.cpp
 * Author            : horcrux2301 <khajuriaharsh729@gmail.com>
 * Date              : 12.01.2019 17:40:30
 * Last Modified Date: 12.01.2019 19:23:25
 */
#include <bits/stdc++.h>
#define ll long long
#define mp(a, b) make_pair(a, b)
#define newline cout << endl;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p)
{
    out << '(' << p.ff << ", " << p.ss << ')';
    return out;
}

template <typename T> ostream& operator<<(ostream& out, vector<T> const& v)
{
    int l = v.size();
    for (int i = 0; i < l - 1; i++)
        out << v[i] << ' ';
    if (l > 0)
        out << v[l - 1];
    return out;
}

template <typename T> void trace(const char* name, T&& arg1) { cout << name << " : " << arg1 << endl; }

template <typename T, typename... Args> void trace(const char* names, T&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | ";
    trace(comma + 1, args...);
}

bool validxy(ll x, ll y, ll a, ll b) { return x >= 0 && y >= 0 && x < a && y < b; }

struct HASH {
    size_t operator()(const pair<ll, ll>& x) const { return hash<long long>()(((ll)x.first) ^ (((long long)x.second) << 32)); }
};

int main()
{
    clock_t tStart = clock();
    int test;
    test = 1;
    // cin >> test;
    while (test--) {
        ll a, b;
        cin >> a >> b;
        vector<string> arr(a);
        for (ll i = 0; i < a; i++)
            cin >> arr[i];

        ll ans = 0;

        bool visitedsharp[a][b];
        for (ll i = 0; i < a; i++) {
            for (ll j = 0; j < b; j++)
                visitedsharp[i][j] = 0;
        }

        bool visited[a][b];
        for (ll i = 0; i < a; i++) {
            for (ll j = 0; j < b; j++) {
                visited[i][j] = 0;
            }
        }

        for (ll ix = 0; ix < a; ix++) {
            for (ll jx = 0; jx < b; jx++) {

                if (arr[ix][jx] == '#' && !visitedsharp[ix][jx]) {

                    visitedsharp[ix][jx] = 1;
                    /* unordered_map<pll, bool, HASH> m; */
                    /* m[{ ix, jx }] = 1; */
                    ll cnt = 0;
                    ll valcnt = 1;
                    queue<pll> q;

                    q.push({ ix, jx });
                    visited[ix][jx] = 1;
                    /* trace("mainx,mainy", ix, jx); */

                    while (!q.empty()) {

                        auto node = q.front();
                        q.pop();
                        ll x = node.ff, y = node.ss;

                        for (ll i = -1; i <= 1; i++) {
                            for (ll j = -1; j <= 1; j++) {
                                if (abs(i) == abs(j))
                                    continue;
                                if (validxy(x + i, y + j, a, b) && !visited[x + i][y + j]) {
                                    if (arr[x][y] == '#' && arr[x + i][y + j] == '.') {
                                        visited[x + i][y + j] = 1;
                                        cnt++;
                                        /* trace("foundx,foundy", x + i, y + j); */
                                        q.push({ x + i, y + j });
                                    } else if (arr[x][y] == '.' && arr[x + i][y + j] == '#') {
                                        q.push({ x + i, y + j });
                                        visited[x + i][y + j] = 1;
                                        /* m[{ x + i, y + j }] = 1; */
                                        visitedsharp[x + i][y + j] = 1;
                                        valcnt++;
                                    }
                                }
                            }
                        }
                    }

                    ans += valcnt * cnt;
                }
            }
        }
        cout << ans << endl;
    }
#ifdef LOCAL_DEFINE
    printf("Time taken: %.2fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
#endif
    return 0;
}


Measured memory_bytes: 768