#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &n) {
  T w = 1;
  n = 0;
  char ch = getchar();
  while (!isdigit(ch) && ch != EOF) {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (isdigit(ch) && ch != EOF) {
    n = (n << 1) + (n << 3) + (ch ^ 48);
    ch = getchar();
  }
  n *= w;
}
template <typename T>
inline void write(T x) {
  unsigned long long y = 0;
  T l = 0;
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (!x) {
    putchar(48);
    return;
  }
  while (x) {
    y = y * 10 + x % 10;
    x /= 10;
    l++;
  }
  while (l) {
    putchar(y % 10 + 48);
    y /= 10;
    l--;
  }
}
template <typename T>
inline void writeln(T x) {
  write(x);
  puts("");
}
template <typename T>
inline void writes(T x) {
  write(x);
  putchar(' ');
}
template <typename T>
inline void checkmax(T &a, T b) {
  a = a > b ? a : b;
}
template <typename T>
inline void checkmin(T &a, T b) {
  a = a < b ? a : b;
}
const int N = 2100;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int tot, ntot, a[N][N], cnt, vis[N][N];
long long sum, ans;
bool pos[N][N];
struct wzy {
  int x, y;
} t[N * N];
queue<pair<int, int> > q, nq, nnq;
inline void bfs(int x, int y, int now) {
  sum = 0;
  vis[x][y] = now;
  q.push(make_pair(x, y));
  tot++;
  t[tot].x = x;
  t[tot].y = y;
  sum++;
  ntot = tot;
  while (!q.empty()) {
    int tx = q.front().first, ty = q.front().second;
    q.pop();
    for (int i = (0); i <= (3); i++) {
      int qx = tx + dx[i], qy = ty + dy[i];
      if (a[tx][ty] != a[qx][qy] || vis[qx][qy]) continue;
      vis[qx][qy] = now;
      tot++;
      t[tot].x = qx;
      t[tot].y = qy;
      sum++;
      q.push(make_pair(qx, qy));
    }
  }
  ans += sum;
  for (int i = (ntot); i <= (tot); i++) {
    for (int k = (0); k <= (3); k++) {
      int qx = t[i].x + dx[k], qy = t[i].y + dy[k];
      if (vis[qx][qy] != now) {
        nq.push(make_pair(t[i].x, t[i].y));
        pos[t[i].x][t[i].y] = 1;
        sum--;
        break;
      }
    }
  }
  while (sum) {
    ans += sum;
    while (!nq.empty()) {
      int tx = nq.front().first, ty = nq.front().second;
      nq.pop();
      for (int i = (0); i <= (3); i++) {
        int qx = tx + dx[i], qy = ty + dy[i];
        if (vis[qx][qy] != now || pos[qx][qy]) continue;
        nnq.push(make_pair(qx, qy));
        pos[qx][qy] = 1;
        sum--;
      }
    }
    while (!nnq.empty()) {
      nq.push(make_pair(nnq.front().first, nnq.front().second));
      nnq.pop();
    }
  }
}
int main() {
  int n, m;
  read(n);
  read(m);
  for (int i = (1); i <= (n); i++) {
    string st;
    cin >> st;
    for (int j = (1); j <= (m); j++) a[i][j] = int(st[j - 1]);
  }
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (m); j++)
      if (!vis[i][j]) {
        ++cnt;
        bfs(i, j, cnt);
      }
  writeln(ans);
  return 0;
}
