#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

bool used[410][410];
int a[410][410];
signed main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++)
    {
        cin >> s[i];
        REP(j,w){
        if(s[i][j]=='#'){
            a[i][j] = 1;
        }
        else{
            a[i][j] = 0;
        }
        }
    }

    int ans = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if(used[i][j]){
                continue;
            }
            used[i][j] = true;
            int B = 0, W = 0;
            queue<pair<int, int>> q;
            q.push(make_pair(i, j));
          //  cerr << i << " " << j << endl;
            while (!q.empty())
            {
                int x = q.front().first;
                int y = q.front().second;
             //   cerr << x << " " << y << endl;
                q.pop();
                if(a[x][y]==1){
                    B++;
                }
                else{
                    W++;
                }
                for (int dx = -1; dx <=1 ; dx++)
                {
                    for (int dy = -1; dy <=1; dy++)
                    {
                        if(dx*dx+dy*dy!=1){
                            continue;
                        }
                       // cerr << "s" << x << x + dx <<  y <<y + dy  << w<<endl;
                      //  cerr << "s" << x << x + dx << (0<=y+dy) << (y + dy<w) << endl;
                        
                        if (0 <= x + dx && x + dx < h && 0<=y + dy  && y + dy < w)
                        {
                          //  cerr << "d" << x<<x+dx<<y<<y+dy<<" " << a[x][y] <<" "<< a[x + dx][y + dy] << endl;
                            
                            if (a[x][y] != a[x + dx][y + dy] && !used[x + dx][y + dy])
                            {
                               // cerr << "a";
                                used[x + dx][y + dy] = true;
                                q.push(make_pair(x + dx, y + dy));
                            }
                        }
                    }
                    
                }
            }
            ans += B * W;
          //  cerr << "cnt"<<B << " " << W << endl;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1920