#include <bits/stdc++.h>
using namespace std;
const int INF = -1000000000, NN = 2005, SS = 505;
int n, m, h[NN], id[NN], len[NN], w[NN][NN], f[NN][NN];
char s[NN][SS];
map<long long, int> ma;
bool cmp(const int &A, const int &B) {
  for (int i = (1); i <= (min(len[A], len[B])); i++)
    if (s[A][i] < s[B][i])
      return 1;
    else if (s[A][i] > s[B][i])
      return 0;
  return len[A] < len[B];
}
int get(int A, int B) {
  for (int i = (1); i <= (min(len[A], len[B])); i++)
    if (s[A][i] != s[B][i]) return i - 1;
  return min(len[A], len[B]);
}
int dfs(int L, int R, int k) {
  if (R - L + 1 < k) return INF;
  if (k <= 1) return 0;
  int id = L, res = INF;
  long long LRk = (long long)L * NN * NN + R * NN + k;
  if (R - L + 1 == k) return f[L][R];
  if (ma[LRk]) return ma[LRk];
  for (int i = (L + 1); i <= (R - 1); i++)
    if (h[i] < h[id]) id = i;
  for (int i = (0); i <= (k); i++) {
    int x = dfs(L, id, i), y = dfs(id + 1, R, k - i);
    if (x > INF && y > INF) res = max(res, x + y + i * (k - i) * h[id]);
  }
  return ma[LRk] = res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (n); i++) scanf("%s", s[i] + 1);
  for (int i = (1); i <= (n); i++) len[i] = strlen(s[i] + 1);
  for (int i = (1); i <= (n); i++) id[i] = i;
  sort(id + 1, id + n + 1, cmp);
  for (int i = (1); i <= (n - 1); i++) h[i] = get(id[i], id[i + 1]);
  for (int i = (1); i <= (n - 1); i++) {
    w[i][i + 1] = h[i];
    for (int j = (i + 2); j <= (n); j++) w[i][j] = min(w[i][j - 1], h[j - 1]);
  }
  for (int j = (2); j <= (n); j++)
    for (int i = (1); i <= (j - 1); i++) w[i][j] += w[i - 1][j];
  for (int i = (1); i <= (n - 1); i++) {
    f[i][i + 1] = h[i];
    for (int j = (i + 2); j <= (n); j++)
      f[i][j] = f[i][j - 1] + w[j - 1][j] - w[i - 1][j];
  }
  printf("%d\n", dfs(1, n, m));
  return 0;
}
