"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 arrSame = new Array(H).fill(null).map(function (_) {
    return new Array(W).fill(0);
  });
  var arrDiff = new Array(H).fill(null).map(function (_) {
    return new Array(W).fill(0);
  });
  var res = 0;

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

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

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

        visited[_h][_w] = true;

        if (!r) {
          queue.push([_h, _w, true, ph, pw]);
        } else {
          if (ph != null) {
            arrSame[ph][pw] += arrDiff[_h][_w];
            arrDiff[ph][pw] += arrSame[_h][_w] + 1;
          }

          continue;
        }

        var here = S[_h][_w];

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

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

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

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

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

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

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

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

      res += arrDiff[h][w];
    }
  }

  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);
  });
}
