# include <bits/stdc++.h>
using namespace std;
# define int long long
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
int h, w;
char b[444][444]; // 盤面
int group[444][444]; // マスがどのグループに含まれるか。マスにグループIDを割り当てて判別する
map<int, int> mp; // mp[グループ番号]: そのグループの'#'が得られるスコア
// `#` -> '.' の順でいける部分を埋めていく
int rec(int y, int x, int t) {
group[y][x] = t;
int ret = 0;
for (int i = 0; i < 4; i++) {
int ny = y + dy[i], nx = x + dx[i];
if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
if (b[y][x] == b[ny][nx]) continue;
if (group[ny][nx] != 0) continue;
int cost = (b[ny][nx] == '.' ? 1 : 0); // 異動先が'.'ならスコアが入る
ret += rec(ny, nx, t) + cost;
}
return ret;
}
signed main() {
cin >> h >> w;
for (int i = 0; i < h; i++) {
cin >> b[i];
}
int ans = 0;
int cnt = 1; // グループ番号
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (b[i][j] == '#') {
if (group[i][j] == 0) { // マスにグループ番号が割り振られていない場合
int score = rec(i, j, cnt); // '#'からいける部分にグループ番号を割り当てる。
ans += score;
mp[cnt] = score; // グループ番号にスコアを登録する。これは、再計算を防ぐためにある
cnt++; // グループ番号をインクリメント
} else { // すでにグループ番号が割り振られている場合
ans += mp[group[i][j]];
}
}
}
}
cout << ans << endl;
return 0;
}