#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;
ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll masu[400][400];
    ll visited[400][400];
    ll H, W;
    cin >> H >> W;
    rep(i, H) {
        string S;
        cin >> S;
        rep(j, S.size()) {
            if (S[j] == '#') masu[i][j] = 1;
            else masu[i][j] = 0;
            visited[i][j] = 0;
        }
    }
    ll ans = 0;
    rep(i, H) {
        rep(j, W) {
            if (masu[i][j] == 1 && visited[i][j] == 0) {
                queue<P> q;
                q.push(make_pair(i,j));
                visited[i][j] = 1;
                ll wcnt = 0;
                ll bcnt = 0;
                while(q.size() > 0) {
                    P tmp = q.front();
                    q.pop();
                    if (masu[tmp.first][tmp.second] == 0) {
                        wcnt++;
                        if (tmp.first-1 >= 0 && visited[tmp.first-1][tmp.second] != 1 && masu[tmp.first-1][tmp.second] == 1) {
                            q.push(make_pair(tmp.first-1, tmp.second));
                            visited[tmp.first-1][tmp.second] = 1;
                        }
                        if (tmp.first+1 < H && visited[tmp.first+1][tmp.second] != 1 && masu[tmp.first+1][tmp.second] == 1) {
                            q.push(make_pair(tmp.first+1, tmp.second));
                            visited[tmp.first+1][tmp.second] = 1;
                        }
                        if (tmp.second-1 >= 0 && visited[tmp.first][tmp.second-1] != 1 && masu[tmp.first][tmp.second-1] == 1) {
                            q.push(make_pair(tmp.first, tmp.second-1));
                            visited[tmp.first][tmp.second-1] = 1;
                        }
                        if (tmp.second+1 < W && visited[tmp.first][tmp.second+1] != 1 && masu[tmp.first][tmp.second+1] == 1) {
                            q.push(make_pair(tmp.first, tmp.second+1));
                            visited[tmp.first][tmp.second+1] = 1;
                        }
                    } else {
                        bcnt++;
                        if (tmp.first-1 >= 0 && visited[tmp.first-1][tmp.second] != 1 && masu[tmp.first-1][tmp.second] == 0) {
                            q.push(make_pair(tmp.first-1, tmp.second));
                            visited[tmp.first-1][tmp.second] = 1;
                        }
                        if (tmp.first+1 < H && visited[tmp.first+1][tmp.second] != 1 && masu[tmp.first+1][tmp.second] == 0) {
                            q.push(make_pair(tmp.first+1, tmp.second));
                            visited[tmp.first+1][tmp.second] = 1;
                        }
                        if (tmp.second-1 >= 0 && visited[tmp.first][tmp.second-1] != 1 && masu[tmp.first][tmp.second-1] == 0) {
                            q.push(make_pair(tmp.first, tmp.second-1));
                            visited[tmp.first][tmp.second-1] = 1;
                        }
                        if (tmp.second+1 < W && visited[tmp.first][tmp.second+1] != 1 && masu[tmp.first][tmp.second+1] == 0) {
                            q.push(make_pair(tmp.first, tmp.second+1));
                            visited[tmp.first][tmp.second+1] = 1;
                        }
                    }
                    
                }
                ans += wcnt * bcnt;
            }
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 2816