#include <iostream>
#include <cstring>
using namespace std;

typedef long long ll;

int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};

int h, w;
string t[402];

ll ans;
int white, black;
bool used[402][402];

void solve(int x, int y) {
  used[y][x] = true;
  if (t[y][x] == '.') {
    white++;
  } else {
    black++;
  }

  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (0 <= nx && nx < w && 0 <= ny && ny < h && !used[ny][nx] &&
        t[ny][nx] != t[y][x]) {
      solve(nx, ny);
    }
  }
}

int main() {
  while (cin >> h >> w) {
    for (int i = 0; i < h; i++) {
      cin >> t[i];
    }
    memset(used, 0, sizeof(used));
    ans = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (t[i][j] != '#' || used[i][j]) {
          continue;
        }

        white = 0;
        black = 0;
        solve(j, i);

        ans += (ll)black * white;
      }
    }
    cout << ans << endl;
  }
}
