#include <bits/stdc++.h>
using namespace std;
const unsigned long long P = 131;
int _min(int x, int y) { return x < y ? x : y; }
long long _max(long long x, long long y) { return x > y ? x : y; }
int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * f;
}
struct tnode {
  int son[26], s, dep;
} t[110 * 510];
int cnt;
struct edge {
  int x, y, next;
} e[110 * 2];
int len, last[110 * 510];
int hh, id, uu[110], gg[110 * 1100];
long long f[110 * 2][110];
int fa[110 * 510], son[110 * 510], dep[110 * 510], tot[110 * 510],
    top[110 * 510];
int K, sta[110 * 2];
char ss[510];
void ins(int x, int y) {
  e[++len].x = x, e[len].y = y;
  e[len].next = last[x], last[x] = len;
}
void ins(int len) {
  int x = 0;
  for (int i = 1; i <= len; i++) {
    int y = ss[i] - 'a';
    if (!t[x].son[y]) t[x].son[y] = ++cnt;
    x = t[x].son[y];
  }
  t[x].s++;
}
void pre_tree_node(int x) {
  tot[x] = 1;
  if (t[x].s) uu[++hh] = x;
  for (int i = 0; i < 26; i++)
    if (t[x].son[i]) {
      int y = t[x].son[i];
      dep[y] = dep[x] + 1;
      fa[y] = x;
      pre_tree_node(y);
      tot[x] += tot[y];
      if (tot[son[x]] < tot[y]) son[x] = y;
    }
}
void pre_tree_edge(int x, int tp) {
  top[x] = tp;
  if (son[x]) pre_tree_edge(son[x], tp);
  for (int i = 0; i < 26; i++)
    if (t[x].son[i]) {
      int y = t[x].son[i];
      if (y != son[x]) pre_tree_edge(y, y);
    }
}
int LCA(int x, int y) {
  int tx = top[x], ty = top[y];
  while (tx != ty) {
    if (dep[tx] > dep[ty]) swap(tx, ty), swap(x, y);
    y = fa[ty], ty = top[y];
  }
  if (dep[x] > dep[y]) swap(x, y);
  return x;
}
void treedp(int x) {
  gg[x] = ++id;
  tot[x] = _min(K, t[x].s);
  for (int i = 1; i <= tot[x]; i++)
    f[gg[x]][i] = (long long)dep[x] * i * (i - 1) / 2;
  for (int k = last[x]; k; k = e[k].next) {
    int y = e[k].y;
    treedp(y);
    for (int i = _min(tot[x], K); i >= 0; i--) {
      for (int j = _min(K - i, tot[y]); j >= 0; j--) {
        f[gg[x]][i + j] = _max(f[gg[x]][i + j], f[gg[x]][i] + f[gg[y]][j] +
                                                    (long long)i * j * dep[x]);
      }
    }
    tot[x] += tot[y];
  }
}
int main() {
  int n = read();
  K = read();
  for (int i = 1; i <= n; i++) {
    scanf("%s", ss + 1);
    ins(strlen(ss + 1));
  }
  pre_tree_node(0);
  pre_tree_edge(0, 0);
  int tp = 0;
  sta[++tp] = uu[1];
  for (int i = 2; i <= hh; i++) {
    int lca = LCA(sta[tp], uu[i]);
    if (lca == sta[tp]) {
      if (sta[tp] != uu[i]) sta[++tp] = uu[i];
      continue;
    }
    while (tp > 1 && dep[sta[tp - 1]] >= dep[lca])
      ins(sta[tp - 1], sta[tp]), --tp;
    if (sta[tp] != lca) ins(lca, sta[tp]), sta[tp] = lca;
    sta[++tp] = uu[i];
  }
  int rt = sta[1];
  while (tp > 1) ins(sta[tp - 1], sta[tp]), --tp;
  memset(tot, 0, sizeof(tot));
  treedp(rt);
  printf("%I64d\n", f[gg[rt]][K]);
  return 0;
}
