#include <bits/stdc++.h>
using namespace std;

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

// ------------------------------------------------------------------------------------------

int h, w;
char b[444][444];
bool ok[444][444];
int kind[444][444];
int dist[444][444];

const int INF = 1e15;
int bfs(int sy, int sx, int cnt) {
  struct P { int y, x; };
  queue<P> que;
  que.push({sy, sx});
  fill(dist[0], dist[111], INF);
  dist[sy][sx] = 0;
  kind[sy][sx] = cnt;

  int ans = -1;
  while (que.size()) {
    P p = que.front(); que.pop();
    int y = p.y, x = p.x;

    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= h || nx < 0 || ny >= w) continue;
      if (b[y][x] == b[ny][nx]) continue;
      if (dist[ny][nx] != INF) continue;
      dist[ny][nx] = dist[y][x] + 1;
      kind[ny][nx] = 1;
      que.push({ny, nx});
    }
  }

  return ans;
}


int rec(int y, int x, char c, int t) {
  ok[y][x] = true;
  kind[y][x] = t;
  int ret = 0;

  rep (i, 4) {
    int ny = y + dy[i], nx = x + dx[i];
    if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
    if (c == b[ny][nx]) continue;
    if (ok[ny][nx]) continue;
    int cost = (b[ny][nx] == '.' ? 1 : 0);
    ret += rec(ny, nx, b[ny][nx], t) + cost;
  }

  return ret;
}

map<int, int> mp;

signed main() {
  cin >> h >> w;
  rep (i, h) {
    cin >> b[i];
  }

  int ans = 0;
  int cnt = 1;
  rep (i, h) {
    rep (j, w) {
      if (b[i][j] == '#') {
        if (kind[i][j] == 0) {
          int score = rec(i, j, b[i][j], cnt);
          ans += score;
          mp[cnt] = score;
          cnt++;
        } else {
          ans += mp[kind[i][j]];
          // dbg2(kind[i][j], mp[kind[i][j]])
        }
      }
    }
  }

  // for (auto x : mp) {
  //   cout << x.first << ", " << x.second << endl;
  // }

  // print2(kind, h, w);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 14464