#include <bits/stdc++.h>
using namespace std;
const long long M1 = 19260817, M2 = 998244353;
int n, m, ans;
char a[610][610];
int cnt[610][610][30], sum[610][610];
pair<long long, long long> H[610][610];
pair<long long, long long> Minus(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> Hash(int *A) {
  pair<long long, long long> res;
  res.first = res.second = 0;
  for (int i = 0; i < 26; i++) {
    res.first = (res.first + res.first * (m + 1) + A[i]) % M1;
    res.second = (res.second + res.second * (m + 1) + A[i]) % M2;
  }
  return res;
}
bool check(int i, int l, int r) {
  int x = sum[i][r] ^ sum[i][l - 1];
  return x == 0 || (!(x - (x & -x)));
}
pair<long long, long long> s[610 << 1];
int p[610 << 1];
void manacher() {
  int id = 0, mx = 0;
  for (int i = 1; i <= n * 2; i++)
    if (s[i].first >= 0) {
      p[i] = mx >= i ? min(p[id * 2 - i], mx - i) : 1;
      while (i - p[i] > 0 && s[i - p[i]] == s[i + p[i]]) p[i]++;
      ans += p[i] / 2;
      if (i + p[i] > mx) {
        mx = i + p[i];
        id = i;
      }
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", a[i] + 1);
    for (int j = 1; j <= m; j++) {
      for (int 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]);
      sum[i][j] = sum[i][j - 1] ^ (1 << (a[i][j] - 1));
    }
  }
  for (int i = 1; i <= m; i++)
    for (int j = i; j <= m; j++) {
      for (int k = 1; k <= n; k++) {
        s[(k << 1) - 1] = make_pair(0, 0);
        if (check(k, i, j))
          s[(k << 1)] = Minus(H[k][j], H[k][i - 1]);
        else
          s[(k << 1)] = make_pair(-1ll * k, -11ll * k);
      }
      manacher();
    }
  printf("%d", ans);
  return 0;
}
