#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
const int P = 1e9 + 7;
const int Q = 998244353;
int s[maxn], t[maxn], len[maxn];
map<pair<long long, long long>, int> ord;
int cnt[maxn][26], bad[maxn], n, m;
char a[maxn][maxn];
long long p[50], q[50], x[maxn], y[maxn];
void init() {
  t[0] = -233333;
  for (int i = 1; i <= 2 * n; i += 2) t[i] = 0, t[i + 1] = s[i / 2 + 1];
  t[2 * n + 1] = 0;
  t[2 * n + 2] = -666667;
}
void manacher() {
  init();
  int mx = 0, po = 0;
  int n = (::n)*2 + 1;
  for (int i = 1; i <= n; i++) {
    if (mx > i)
      len[i] = min(mx - i, len[2 * po - i]);
    else
      len[i] = 1;
    while (t[i - len[i]] == t[i + len[i]]) len[i]++;
    if (len[i] + i > mx) {
      mx = len[i] + i;
      po = i;
    }
  }
}
int work(int l, int r) {
  int cur = 0, bad_cnt = 0;
  ord.clear();
  for (int i = 1; i <= n; i++) {
    int c = a[i][r] - 'a';
    cnt[i][c]++;
    if (cnt[i][c] & 1)
      bad[i]++;
    else
      bad[i]--;
    x[i] = (x[i] + p[c]) % P;
    y[i] = (y[i] + q[c]) % Q;
    if (bad[i] >= 2) {
      s[i] = -(++bad_cnt);
      continue;
    }
    pair<long long, long long> t = make_pair(x[i], y[i]);
    if (!ord.count(t)) ord[t] = ++cur;
    s[i] = ord[t];
  }
  manacher();
  int ans = 0;
  for (int i = 1; i <= 2 * n + 1; i++)
    if (t[i] >= 0) ans += len[i] / 2;
  return ans;
}
int main() {
  cin >> n >> m;
  getchar();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) a[i][j] = getchar();
    getchar();
  }
  long long ans = 0;
  p[0] = q[0] = 1;
  for (int i = 1; i < 26; i++) {
    p[i] = p[i - 1] * 19260817 % P;
    q[i] = q[i - 1] * 19260817 % Q;
  }
  for (int i = 1; i <= m; i++) {
    memset(cnt, 0, sizeof(cnt));
    memset(bad, 0, sizeof(bad));
    memset(x, 0, sizeof(x));
    memset(y, 0, sizeof(y));
    for (int j = i; j <= m; j++) ans += work(i, j);
  }
  cout << ans << endl;
  return 0;
}
