#include <cstdio>
#include <cmath>
#include <climits>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <fstream>
#include <functional>
#include <utility>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <iomanip>
#define memtst(x) (sizeof(x) / 1024. / 1024.)
#define mem0(x) memset((x), 0, (sizeof x))
#define meminf(x) memset((x), INF, (sizeof x))
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define pf(x) push_front(x)
#define pq std::priority_queue
#define iter iterator
#define mp(x, y) std::make_pair((x), (y))
#define fst first
#define sec second
#define lc(x) ((x) * 2)
#define rc(x) ((x) * 2 + 1) 
#define md(x, y) (((x) + (y)) / 2)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair <int, int> pii;
const double PI = acos(-1);
const double EPS = 1e-6;
const ll MOD = 1000000007;
const ll INF = 0x3F3F3F3F;
template <typename T>
inline T Abs(T x)
{
    return x < 0 ? x * -1 : x;
}
template <typename T>
inline T Max(T x, T y, T z)
{
    return std::max(std::max(x, y), z);
}
template <typename T>
inline T Min(T x, T y, T z)
{
    return std::min(std::min(x, y), z);
}
template <typename T>
inline T Ckmax(T &x, T y)
{
    return x = std::max(x, y);
}
template <typename T>
inline T Ckmin(T &x, T y)
{
    return x = std::min(x, y);
}
template <typename T>
inline T Sqr(T x)
{
    return x * x;
}
template <typename T>
inline T Pow(T x, T y)
{
    T r = 1;
    while (y > 0)
    {
        if (y % 2 > 0)
            (r *= x) %= MOD;
        (x *= x) %= MOD;
        y /= 2;
    }
    return r % MOD;
}
template <typename T>
T Pow(T x, T y, T z)
{
    T r = 1;
    while (y > 0)
    {
        if (y % 2 > 0)
            (r *= x) %= z;
        (x *= x) %= z;
        y /= 2;
    }
    return r % z;
}
template <typename T>
inline T gcd(T x, T y)
{
    return y > 0 ? gcd(y, x % y) : x;
}
template <typename T>
inline T lcm(T x, T y)
{
    return x / gcd(x, y) * y;
}
inline void cinspu(void)
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
}
inline ll read(void)
{
    char x;
    while (x = getchar(), x != '-' && !isdigit(x))
        ;
    char flg = x == '-';
    ll num = (flg ? getchar() : x) - '0';
    while (isdigit(x = getchar()))
        (num *= 10) += x - '0';
    return flg ? -num : num;
}
const int N = 400 + 10;
const int d[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
char vis[N][N], a[N][N], use[N][N];
char m;
int b, c, h, w;
void dfs(int x, int y)
{
	if (a[x][y] == m)
	{
		use[x][y] = 1;
		++b;
	}
	else if (!vis[x][y]) 
		++c;
	vis[x][y] = 1;
	for (int i = 0; i < 4; ++i)
	{
		int p = x + d[i][0], q = y + d[i][1];
		if (p && q && p <= h && q <= w && (a[p][q] != m || !vis[p][q]) && a[p][q] != a[x][y])
			dfs(p, q);
	}
}
int main()
{
	cinspu();
	std::cin >> h >> w;
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j)
			std::cin >> a[i][j];
	int cnt = 0;
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j)
			if (a[i][j] == '.')
				++cnt;
	if (cnt < h * w - cnt)
	{
		m = '.';
	}
	else
	{
		m = '#';
	}
	ll ans = 0;
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j)
			if (!use[i][j] && a[i][j] == m)
			{
				mem0(vis);
				b = c = 0;
				dfs(i, j);
				ans += (ll)b * c;
			}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 8192