#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << '\n';
  err(++it, args...);
}
long long powMod(long long x, long long y) {
  long long p = 1;
  while (y) {
    if (y % 2) {
      p = (p * x) % ((long long)1e9 + 7);
    }
    y /= 2;
    x = (x * x) % ((long long)1e9 + 7);
  }
  return p;
}
long long CpowMod(long long x, long long y, long long w) {
  long long p = 1;
  while (y) {
    if (y % 2) {
      p = (p * x) % w;
    }
    y /= 2;
    x = (x * x) % w;
  }
  return p;
}
long long invMod(long long x) { return powMod(x, ((long long)1e9 + 7) - 2); }
long long CinvMod(long long x, long long w) { return CpowMod(x, w - 2, w); }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long exGcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    y = 0;
    x = 1;
    return a;
  }
  long long xtmp, ytmp;
  long long g = exGcd(b, a % b, xtmp, ytmp);
  x = ytmp;
  y = xtmp - (a / b) * ytmp;
  return g;
}
long long a[2000][2000];
queue<pair<int, int>> qp;
long long n, m;
long long mi[] = {1, -1, 0, 0};
long long mj[] = {0, 0, 1, -1};
bool ok(int x, int y) { return ~x && x < n && ~y && y < m; }
void solve() {
  cin >> n >> m;
  string s[n];
  for (long long i = 0; i <= n - 1; i++) {
    cin >> s[i];
  }
  long long ans = 0;
  for (long long i = 0; i <= n - 1; i++) {
    for (long long j = 0; j <= m - 1; j++) {
      for (long long k = 0; k <= 3; k++) {
        long long ii = mi[k] + i;
        long long jj = mj[k] + j;
        if (!ok(ii, jj) || s[ii][jj] != s[i][j]) {
          a[i][j] = 1;
        }
      }
      if (a[i][j]) {
        qp.push({i, j});
      }
    }
  }
  while (!qp.empty()) {
    long long i = qp.front().first;
    long long j = qp.front().second;
    qp.pop();
    for (long long k = 0; k <= 3; k++) {
      long long ii = mi[k] + i;
      long long jj = mj[k] + j;
      if (ok(ii, jj) && !a[ii][jj]) {
        a[ii][jj] = a[i][j] + 1;
        qp.push({ii, jj});
      }
    }
    ans += a[i][j];
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(20);
  solve();
  return 0;
}
