#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1000000000;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
struct IOSetup {
  IOSetup() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(12);
  }
} iosetup;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++)
    os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
int d[2010][2010];
signed main() {
  int h, w;
  cin >> h >> w;
  string s[h];
  for (int i = 0; i < (h); i++) cin >> s[i];
  using P = pair<int, int>;
  queue<P> que;
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) {
      if (i == 0 or j == 0 or i == h - 1 or j == w - 1) {
        que.push(P(i, j));
        d[i][j] = 1;
        continue;
      }
      bool f = false;
      for (int k = 0; k < (4); k++) {
        int ni = i + dx[k], nj = j + dy[k];
        if (s[i][j] != s[ni][nj]) {
          f = true;
        }
      }
      if (f) {
        d[i][j] = 1;
        que.push(P(i, j));
      }
    }
  while (!que.empty()) {
    auto [i, j] = que.front();
    que.pop();
    for (int k = 0; k < (4); k++) {
      int ni = i + dx[k], nj = j + dy[k];
      if (0 <= ni and ni < h and 0 <= nj and nj < w) {
        if (d[ni][nj] == 0) {
          d[ni][nj] = d[i][j] + 1;
          que.push(P(ni, nj));
        }
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) ans += d[i][j];
  cout << ans << endl;
  return 0;
}
