#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; }
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; }
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; }
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
void print(void) { cout << endl; }
template <class Head> void print(Head&& head) { cout << head; print(); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); }
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }

int main() {
	ll H, W; cin >> H >> W;
	V<string> S(H);
	REP(i, H) cin >> S[i];

	V<V<ll>> grid(H, V<ll>(W, -1));

	ll cnt = 1;
	REP(i,H){
		REP(j,W){
			if (grid[i][j] != -1) continue;

			queue<P<ll,ll>> q;
			q.push({ i,j });
			grid[i][j] = cnt;

			while(q.size()){
				ll y = q.front().first;
				ll x = q.front().second;
				q.pop();
				if(0 < y && grid[y-1][x] == -1 && S[y-1][x]!=S[y][x]){
					q.push({ y - 1,x });
					grid[y - 1][x] = cnt;

				}
				if (y < H-1 && grid[y + 1][x] == -1 && S[y + 1][x] != S[y][x]) {
					q.push({ y + 1,x });
					grid[y + 1][x] = cnt;
				}
				if (0 < x && grid[y][x - 1] == -1 && S[y][x - 1] != S[y][x]) {
					q.push({ y,x - 1 });
					grid[y][x - 1] = cnt;
				}
				if (x < W - 1 && grid[y][x + 1] == -1 && S[y][x + 1] != S[y][x]) {
					q.push({ y,x + 1 });
					grid[y][x + 1] = cnt;
				}
			}
			cnt++;
		}
	}
	V<ll> b(cnt, 0), w(cnt, 0);
	REP(i, H) {
		REP(j, W){
			if(S[i][j]=='#'){
				b[grid[i][j] - 1]++;
			}
			if (S[i][j] == '.') {
				w[grid[i][j] - 1]++;
			}
		}
	}

	ll sum = 0;
	REP(i,cnt){
		sum += b[i] * w[i];
	}
	cout << sum << endl;




	


	return 0;
}

Measured memory_bytes: 3712