#include <bits/stdc++.h>
using namespace std;
template <class t>
inline t read(t &x) {
  bool f = 0;
  char c = getchar();
  x = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
template <class t>
inline void write(t x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
  }
}
const int N = 2005;
int lc[N], rc[N], st[N], top, n, k, lcp[N], f[N][N];
string s[N];
void dico(int x, int l, int r) {
  if (lc[x]) dico(lc[x], l, x - 1);
  if (rc[x]) dico(rc[x], x + 1, r);
  for (int i = 0; i <= k && i <= x - l + 1; i++)
    for (int j = 0; j <= k && j <= r - x + 1 && i + j <= k; j++)
      f[x][i + j] =
          max(f[x][i + j], f[lc[x]][i] + f[rc[x]][j] + lcp[x] * i * j);
}
signed main() {
  read(n);
  read(k);
  for (int i = 1; i <= n; i++) cin >> s[i];
  sort(s + 1, s + 1 + n);
  for (int i = 1; i < n; i++) {
    for (lcp[i] = 0; lcp[i] < s[i].size() && lcp[i] < s[i + 1].size() &&
                     s[i][lcp[i]] == s[i + 1][lcp[i]];
         lcp[i]++)
      ;
  }
  n--;
  for (int i = 1; i <= n; i++) {
    while (top && lcp[st[top]] > lcp[i]) lc[i] = st[top--];
    if (top) rc[st[top]] = i;
    st[++top] = i;
  }
  int rt = st[1];
  dico(rt, 1, n);
  write(f[rt][k]);
}
