"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++) {
      if (visited[h][w]) {
        continue;
      }

      rec(h, w, 0, 0);
    }
  }

  console.log(res);

  function rec(h, w, same, diff) {
    if (visited[h][w]) {
      return;
    }

    visited[h][w] = true;
    var here = S[h][w];
    res += diff;

    if (h > 0) {
      var up = S[h - 1][w];

      if (here !== up) {
        rec(h - 1, w, diff, same + 1);
      }
    }

    if (w > 0) {
      var left = S[h][w - 1];

      if (here !== left) {
        rec(h, w - 1, diff, same + 1);
      }
    }

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

      if (here !== down) {
        rec(h + 1, w, diff, same + 1);
      }
    }

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

      if (here !== right) {
        rec(h, w + 1, diff, same + 1);
      }
    }
  }

  return;
  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 result = 0;

  for (var _h = 0; _h < H; _h++) {
    for (var _w = 0; _w < W; _w++) {
      var here = S[_h][_w];

      if (_h > 0) {
        // check upper tile.
        var up = S[_h - 1][_w];

        if (here !== up) {
          arrSame[_h][_w] += arrDiff[_h - 1][_w];
          arrDiff[_h][_w] += arrSame[_h - 1][_w] + 1;
        }
      }

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

        if (here !== left) {
          arrSame[_h][_w] += arrDiff[_h][_w - 1];
          arrDiff[_h][_w] += arrSame[_h][_w - 1] + 1;
        }
      }

      result += arrDiff[_h][_w];
      console.log(_h, _w, arrSame[_h][_w], arrDiff[_h][_w]);
    }
  }

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