#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define rsort_v(v) std::sort(v.rbegin(), v.rend())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //

#if 1
int S[500][500];
ll H, W;
vector<pair<ll, ll>> cnt_arr;

bool is_in(ll y, ll x) {
	return 0 <= y && y < H && 0 <= x && x < W;
}
#if 0
pair<int, int> solve(int y, int x, int type) {
	if (!is_in(y, x) || S[y][x] < 0) return { 0, 0 };
	if (type == S[y][x])
		return { 0, 0 };
	int nt = S[y][x];
	S[y][x] = -1;
	/*loop(y_, H) {
		loop(x_, W)
			if (y_ == y && x_ == x)
				cerr << "(*)";
			else
				cerr << (S[y_][x_] < 0 ? "" : " ") << S[y_][x_] << " ";
		cerr << endl;
	}
	cerr << " > " << nt << "(" << y << ", " << x << ")" << endl;
	cerr << "----" << endl; */
	auto a = solve(y - 1, x, nt);
	auto b = solve(y + 1, x, nt);
	auto c = solve(y, x - 1, nt);
	auto d = solve(y, x + 1, nt);
	pair<int, int> res {
		a.first  + b.first  + c.first  + d.first + (nt == 0),
		a.second + b.second + c.second + d.second + (nt == 1)
	};
	/*cerr << res.first << " - " << res.second << " -- " << nt << endl;
	cerr << "----" << endl;
	cerr << "----" << endl;*/
	return res;
}
#endif
pair <ll, ll> solve(ll y, ll x, int type) {
	if (S[y][x] == -1 || S[y][x] == type)
		return make_pair(0ll, 0ll);
	int nt = S[y][x];
	S[y][x] = -1;
	auto res = (nt == 1 ? make_pair(0ll, 1ll) : make_pair(1ll, 0ll));
	if (is_in(y - 1, x)) {
		auto t = solve(y - 1, x, nt);
		res.first += t.first;
		res.second += t.second;
	}
	if (is_in(y + 1, x)) {
		auto t = solve(y + 1, x, nt);
		res.first += t.first;
		res.second += t.second;
	}
	if (is_in(y, x - 1)) {
		auto t = solve(y, x-1, nt);
		res.first += t.first;
		res.second += t.second;
	}
	if (is_in(y, x + 1)) {
		auto t = solve(y, x + 1, nt);
		res.first += t.first;
		res.second += t.second;
	}
	return res;
}

int main() {
	cin >> H >> W;
	loop(y, H) {
		in(string, s);
		loop(x, W)
			S[y][x] = (s[x] == '#');
	}
	loop(y, H)
		loop(x, W)
		if (S[y][x] >= 0) {
			cnt_arr.push_back(solve(y, x, -1));
			//cerr << endl << endl;
		}
	ll ans = 0;
	//cerr << "----" << endl;
	for (auto c : cnt_arr) {
		//cerr << " > " << c.first << " - " << c.second << endl;
		ans += ll(c.first) * ll(c.second);
	}
	cout << ans << endl;
}
#endif

#if 0
int main() {
	in(ll, N, Q);
	in_v(ll, A, Q);
	sort_v(A);
	vector<ll> sA(Q + 1, 0);
	{
		ll t = 0;
		loop(i, Q + 1) {
			sA[i] = t;
			t += A[i];
		}
	}

	
}
#endif

Measured memory_bytes: 8576