#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  char c = getchar();
  int f = 0;
  for (; !isdigit(c); c = getchar()) f |= c == '-';
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ '0');
  if (f) x = -x;
}
template <typename T>
void write(T x, char ed = '\n') {
  static short st[30], tp;
  if (x < 0) putchar('-'), x = -x;
  do st[++tp] = x % 10, x /= 10;
  while (x);
  while (tp) putchar(st[tp--] | '0');
  putchar(ed);
}
template <typename T>
inline void Mn(T &x, T y) {
  if (x > y) x = y;
}
template <typename T>
inline void Mx(T &x, T y) {
  if (x < y) x = y;
}
const int N = 1000050;
int ch[N][26], siz[N], id[N], Id, cnt, n, k;
long long f[2005][2005];
char s[N];
void dfs(int x, long long dep) {
  if (siz[x]) {
    memset(f[id[x] = ++Id], -0x3f, sizeof(f[0]));
    for (int j = 0; j <= siz[x]; ++j) f[Id][j] = dep * j * (j - 1) / 2;
  }
  for (int i = 0, y; i < 26; ++i)
    if (ch[x][i]) {
      dfs(y = ch[x][i], dep + 1);
      if (!id[x]) {
        siz[x] += siz[y], id[x] = id[y];
        continue;
      }
      for (int j = siz[x]; j >= 0; --j)
        for (int k = siz[y]; k >= 0; --k)
          Mx(f[id[x]][j + k], f[id[x]][j] + f[id[y]][k] + dep * j * k);
      siz[x] += siz[y], Mn(siz[x], k);
    }
}
int main() {
  read(n), read(k);
  for (int i = 1, len; i <= n; ++i) {
    scanf("%s", s + 1), len = strlen(s + 1);
    int p = 0;
    for (int j = 1; j <= len; ++j) {
      int c = s[j] - 'a';
      if (!ch[p][c]) ch[p][c] = ++cnt;
      p = ch[p][c];
    }
    ++siz[p];
  }
  dfs(0, 0), write(f[id[0]][k]);
  return 0;
}
