/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

//code by lynmisakura.wish to be accepted!
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

/***************************/
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;

//const long long INF = 1LL << 55;

#define itn ll
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

class CAlternatingPath {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    int visited[410][410];
    char grid[410][410];
    int pa[410*410];
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};
    ll h,w;
    ll ans;
    ll bl,wh;
    void dfs(int x,int y){
        visited[x][y]++;
        if(grid[x][y] == '#')bl++;else wh++;
        rep(d,4){
            int nx = x + dx[d];
            int ny = y + dy[d];
            if(nx >= 0 and nx < h and ny >= 0 and ny < w){
                if(!visited[nx][ny] and grid[nx][ny] != grid[x][y]){
                    dfs(nx,ny);
                }
            }
        }
        //visited[x][y]--;
    }
    void solve(std::istream& cin, std::ostream& cout) {
        cin >> h >> w;
        rep(i,h){
            string s;cin >> s;
            rep(j,w) visited[i][j] = 0,grid[i][j] = s[j];
        }
        ans = 0;
        rep(i,h)rep(j,w){
            if(!visited[i][j]){
                bl = wh = 0;
                dfs(i,j);
                //cout << count << endl;
                ans += bl * wh;
                //cout << i << " " << j << " " <<  bl << " " << wh << endl;
            }
        }
        cout << ans << endl;
    }
};

int main() {
	CAlternatingPath solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 9856