#include <bits/stdc++.h>
using namespace std;
bool _S;
int son[2005 * 505][26], f[14005][2005], Link[2005 * 505], size[2005 * 505];
short step[2005 * 505];
char a[505];
int n, tot, i, k;
bool _T;
void Insert(char *a) {
  int p = 1;
  for (int i = 0; a[i]; i++) {
    int &v = son[p][a[i] - 'a'];
    if (!v) step[v = ++tot] = step[p] + 1;
    p = v;
  }
  size[p]++;
}
void DP(int x) {
  int num = 0, ID = 0, id;
  for (int i = 0; i < 26; i++)
    if (son[x][i]) DP(son[x][i]), ID = son[x][i], num++;
  if (!size[x] && num == 1) {
    Link[x] = Link[ID];
    size[x] = size[ID];
    return;
  }
  Link[x] = id = ++tot;
  for (int u = 0; u <= size[x]; u++) f[tot][u] = u * (u - 1) / 2 * step[x];
  if (!num) return;
  for (int i = 0, y; i < 26; i++)
    if (y = son[x][i]) {
      ID = Link[y];
      for (int u = min(k, size[x]); u >= 0; u--)
        for (int v = 0; v <= size[y] && u + v <= k; v++)
          f[id][u + v] =
              max(f[id][u + v], f[id][u] + f[ID][v] + step[x] * u * v);
      size[x] += size[y];
    }
}
int main() {
  memset(f, 200, sizeof(f));
  scanf("%d%d", &n, &k);
  tot = 1;
  for (i = 1; i <= n; i++) scanf("%s", a), Insert(a);
  tot = 0;
  DP(1);
  printf("%d\n", f[Link[1]][k]);
}
