#include <bits/stdc++.h>
using namespace std;
struct FastIO {
  inline FastIO& operator>>(int& x) {
    x = 0;
    char f = 0, ch = getchar();
    while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
    while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
    return x = (f ? -x : x), *this;
  }
  inline FastIO& operator>>(long long& x) {
    x = 0;
    char f = 0, ch = getchar();
    while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
    while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
    return x = (f ? -x : x), *this;
  }
  inline FastIO& operator>>(double& x) {
    x = 0;
    char f = 0, ch = getchar();
    double d = 0.1;
    while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
    while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
    if (ch == '.') {
      ch = getchar();
      while (ch <= '9' && ch >= '0')
        x += d * (ch ^ 48), d *= 0.1, ch = getchar();
    }
    return x = (f ? -x : x), *this;
  }
} read;
void file() {}
unsigned int log2(int x) {
  unsigned int ret;
  __asm__ __volatile__("bsrl %1, %%eax" : "=a"(ret) : "m"(x));
  return ret;
}
inline long long mul(long long a, long long b) {
  long long d = (long long)(a * (double)b / (int)(1e9 + 7) + 0.5);
  long long ret = a * b - d * (int)(1e9 + 7);
  if (ret < 0) ret += (int)(1e9 + 7);
  return ret;
}
int cnt[666][666][26];
char a[666][666];
int t[666][666];
int n, m;
const long long M1 = 19260817, M2 = 998244353;
pair<long long, long long> C(const pair<long long, long long>& x,
                             const pair<long long, long long>& y) {
  return make_pair((x.first - y.first + M1) % M1,
                   (x.second - y.second + M2) % M2);
}
pair<long long, long long> H[666][666];
pair<long long, long long> Hash(int* x) {
  pair<long long, long long> ret;
  ret.first = ret.second = 0;
  for (int i = 0; i < 26; i++)
    (ret.first = ret.first * (m + 1) + x[i]) %= M1,
        (ret.second = ret.second * (m + 1) + x[i]) %= M2;
  return ret;
}
bool check(int i, int l, int r) {
  int x = t[i][l - 1] ^ t[i][r];
  return (!x) || (!(x - (x & (-x))));
}
pair<long long, long long> s[666];
int len[666];
long long ans;
void manacher() {
  int mid = 0, R = 0;
  for (int i = 1; i <= n * 2; i++)
    if (s[i].first >= 0) {
      len[i] = 1;
      if (R >= i) len[i] = min(len[mid * 2 - i], R - i + 1);
      while (len[i] < i && s[i + len[i]] == s[i - len[i]]) ++len[i];
      ans += len[i] / 2;
      if (i + len[i] - 1 > R) R = i + len[i] - 1, mid = i;
    }
}
int main() {
  file();
  int i, j, k;
  read >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> ((a[i]) + 1);
    for (j = 1; j <= m; j++) {
      for (k = 0; k < 26; k++) cnt[i][j][k] = cnt[i][j - 1][k];
      cnt[i][j][a[i][j] - 'a']++;
      H[i][j] = Hash(cnt[i][j]);
      t[i][j] = t[i][j - 1] ^ (1 << (a[i][j] - 1));
    }
  }
  for (i = 1; i <= m; i++)
    for (j = i; j <= m; j++) {
      for (k = 1; k <= n; k++)
        s[k * 2 - 1] = make_pair(0, 0),
                  s[k * 2] =
                      (check(k, i, j)
                           ? C(H[k][j], H[k][i - 1])
                           : (pair<long long, long long>)make_pair(-k, -k));
      manacher();
    }
  cout << ans;
}
