#include <bits/stdc++.h>
using namespace std;
const int N = 2100;
const double eps = 1e-9;
const int oo = 1000000000;
int id, n, k, f[N], g[N][N], b[N][N], ff[N * 4][N];
char s[N][N];
inline int cmp(const void *p, const void *q) {
  return strcmp((char *)p, (char *)q);
}
void init() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    char ss[N];
    scanf("%s", s[i]);
  }
  qsort(s, n, sizeof(s[0]), cmp);
}
int counts(int x, int y, int k) {
  if (x > y || k <= 1) {
    return 0;
  }
  if (b[x][y] == -1) {
    b[x][y] = id++;
  }
  if (ff[b[x][y]][k] != -1) {
    return ff[b[x][y]][k];
  }
  int a = g[x + 1][y];
  for (int i = 0; i <= k; ++i)
    if (a - 1 - x + 1 >= i && y - a + 1 >= k - i) {
      int p = counts(x, a - 1, i), q = counts(a, y, k - i);
      ff[b[x][y]][k] = max(ff[b[x][y]][k], p + q + i * (k - i) * f[a]);
    }
  return ff[b[x][y]][k];
}
void solve() {
  for (int i = 1; i < n; ++i) {
    f[i] = 0;
    for (int j = 0; s[i][j] && s[i - 1][j] && s[i][j] == s[i - 1][j]; ++j) {
      ++f[i];
    }
  }
  for (int i = 1; i < n; ++i) {
    g[i][i] = i;
    for (int j = i + 1; j < n; ++j) {
      g[i][j] = f[j] < f[g[i][j - 1]] ? j : g[i][j - 1];
    }
  }
  memset(ff, -1, sizeof(ff));
  memset(b, -1, sizeof(b));
  id = 0;
  int ans = counts(0, n - 1, k);
  printf("%d\n", ans);
}
int main() {
  init();
  solve();
  return 0;
}
