"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function main(input) {
  var lines = input.split('\n');

  var _splitNum = splitNum(lines[0]),
      _splitNum2 = _slicedToArray(_splitNum, 2),
      H = _splitNum2[0],
      W = _splitNum2[1];

  var S = lines.slice(1, H + 1);
  var visited = new Array(H).fill(null).map(function (_) {
    return new Array(W).fill(false);
  });
  var res = 0;

  for (var h = 0; h < H; h++) {
    for (var w = 0; w < W; w++) {
      var queue = [[h, w]];
      var bc = 0,
          wc = 0;

      while (queue.length > 0) {
        var _queue$pop = queue.pop(),
            _queue$pop2 = _slicedToArray(_queue$pop, 2),
            _h = _queue$pop2[0],
            _w = _queue$pop2[1];

        if (visited[_h][_w]) {
          continue;
        }

        visited[_h][_w] = true;
        var here = S[_h][_w];

        if (here === '.') {
          wc++;
        } else {
          bc++;
        }

        if (_h > 0) {
          var up = S[_h - 1][_w];

          if (here !== up) {
            queue.push([_h - 1, _w]);
          }
        }

        if (_w > 0) {
          var left = S[_h][_w - 1];

          if (here !== left) {
            queue.push([_h, _w - 1]);
          }
        }

        if (_h < H - 1) {
          var down = S[_h + 1][_w];

          if (here !== down) {
            queue.push([_h + 1, _w]);
          }
        }

        if (_w < W - 1) {
          var right = S[_h][_w + 1];

          if (here !== right) {
            queue.push([_h, _w + 1]);
          }
        }
      }

      res += bc * wc;
    }
  }

  console.log(res);
  return;
  var result = 0;

  for (var _h2 = 0; _h2 < H; _h2++) {
    for (var _w2 = 0; _w2 < W; _w2++) {
      var _here = S[_h2][_w2];

      if (_h2 > 0) {
        // check upper tile.
        var _up = S[_h2 - 1][_w2];

        if (_here !== _up) {
          arrSame[_h2][_w2] += arrDiff[_h2 - 1][_w2];
          arrDiff[_h2][_w2] += arrSame[_h2 - 1][_w2] + 1;
        }
      }

      if (_w2 > 0) {
        var _left = S[_h2][_w2 - 1];

        if (_here !== _left) {
          arrSame[_h2][_w2] += arrDiff[_h2][_w2 - 1];
          arrDiff[_h2][_w2] += arrSame[_h2][_w2 - 1] + 1;
        }
      }

      result += arrDiff[_h2][_w2];
      console.log(_h2, _w2, arrSame[_h2][_w2], arrDiff[_h2][_w2]);
    }
  }

  console.log(result);
}

function gcd(a, b) {
  if (a < b) return gcd(a, b);
  if (b === 0) return a;
  var r = a % b;
  return gcd(b, r);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function splitNum(line) {
  return line.split(/\s+/).map(function (n) {
    return parseInt(n);
  });
}


Measured memory_bytes: 63536