#include <bits/stdc++.h>
inline int getInt() {
  register int x = 0;
  register char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
  return x;
}
int n, m;
int son[500000][26], cnt[500000], deep[500000], root = 0, tot = 1;
inline void Insert() {
  int p = root;
  register char ch = getchar();
  while (!isalpha(ch)) ch = getchar();
  for (; isalpha(ch); ch = getchar()) {
    int c = ch - 'a';
    p = ~son[p][c] ? son[p][c] : (deep[son[p][c] = tot] = deep[p] + 1, tot++);
  }
  cnt[p]++;
}
int head[500000], next[500000], to[500000], val[500000], _T = 0, _I = 1;
inline void addEdge(int u, int v, int w) {
  if (v == -1 || u == -1 || u == v) return;
  next[_T] = head[u];
  to[_T] = v;
  val[_T] = w;
  head[u] = _T++;
}
int size[500000], top[500000];
void build(int x, int tp, int sum) {
  top[x] = tp;
  sum += cnt[x];
  int count = 0;
  for (int i = 0; i < 26; i++)
    if (~son[x][i]) count++;
  if (count == 0) {
    size[x] = sum;
    addEdge(top[x], x, deep[x] - deep[top[x]]);
  } else if (count == 1 && cnt[x] == 0) {
    for (int i = 0; i < 26; i++)
      if (~son[x][i]) build(son[x][i], top[x], sum);
  } else {
    size[x] = sum;
    addEdge(top[x], x, deep[x] - deep[top[x]]);
    for (int i = 0; i < 26; i++)
      if (~son[x][i]) build(son[x][i], x, 0);
  }
}
void print(int x, int deep = 0, int len = 0) {
  for (int i = 0; i < deep; i++) putchar(' ');
  printf("{%d %d %d}\n", len, x, size[x]);
  for (int i = head[x]; ~i; i = next[i]) print(to[i], deep + 2, val[i]);
}
int f[2010 << 1][2010 << 1], __index = 0;
int DP(int x, int len) {
  int cur = __index++, ret;
  for (int i = 1; i <= size[x]; i++) f[cur][i] = len * i * (i - 1) / 2;
  for (int i = head[x]; ~i; i = next[i]) {
    ret = DP(to[i], val[i]);
    size[x] += size[to[i]];
    for (int j = size[x]; j >= 0; j--) {
      for (int k = 0; k <= size[to[i]] && k <= j; k++) {
        f[cur][j] =
            std::max(f[cur][j], f[cur][j - k] + f[ret][k] + len * (j - k) * k +
                                    len * k * (k - 1) / 2);
      }
    }
  }
  return cur;
}
int main() {
  memset(son, -1, sizeof(son));
  memset(head, -1, sizeof(head));
  n = getInt();
  m = getInt();
  while (n--) Insert();
  build(root, root, 0);
  printf("%d\n", f[DP(root, 0)][m]);
  return 0;
}
