#include <bits/stdc++.h>
using namespace std;
const int x[] = {1000000007, 998244353, 99999987, 66662333};
const int MaxN(703), Base = 131;
int s1[MaxN], s2[MaxN], p[26], s0[MaxN], t[MaxN][26], tot[MaxN];
int pd[MaxN];
long long Manacher(int len) {
  int M = 1;
  long long ans = 0;
  s2[0] = -100000, s2[1] = -100001;
  for (int i = 1; i <= len; i++) {
    s2[++M] = s1[i];
    s2[++M] = -100001;
  }
  int id = 0, mx = 0;
  for (int i = 1; i <= M; i++) {
    if (i < mx)
      pd[i] = min(pd[2 * id - i], mx - i);
    else
      pd[i] = 1;
    while (s2[i + pd[i]] == s2[i - pd[i]]) ++pd[i];
    if (mx < i + pd[i]) {
      mx = i + pd[i];
      id = i;
    }
    if (i > 1 && (s2[i] >= 0 || s2[i] == -100000 || s2[i] == -100001))
      ans += pd[i] / 2;
  }
  return ans;
}
char s[MaxN][MaxN];
int main() {
  int n, m;
  long long ans = 0;
  srand(time(0));
  int Mod = x[rand() % 4];
  p[0] = 1;
  for (int i = 1; i < 26; i++) p[i] = (long long)p[i - 1] * Base % Mod;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int l = 1; l <= m; l++) {
    for (int i = 1; i <= n; i++) s1[i] = tot[i] = 0;
    memset(t, 0, sizeof(t));
    for (int r = l; r <= m; r++) {
      for (int i = 1; i <= n; i++) {
        int x = s[i][r] - 'a';
        s1[i] =
            ((long long)s1[i] - (long long)p[x] * t[i][x] % Mod + Mod) % Mod;
        t[i][x]++;
        s0[i] = s1[i] =
            ((long long)s1[i] + (long long)p[x] * t[i][x] % Mod + Mod) % Mod;
        tot[i] += t[i][x] % 2 ? 1 : -1;
      }
      bool f = 0;
      for (int i = 1; i <= n; i++)
        if (tot[i] <= 1)
          f = 1;
        else
          s1[i] = -i;
      ans += Manacher(n);
      for (int i = 1; i <= n; i++) s1[i] = s0[i];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
