#include <bits/stdc++.h>
using namespace std;
struct box {
  char str[505];
} s[2005];
int lcp[2005];
int comp(const void *p, const void *q) {
  return strcmp((*(struct box *)p).str, (*(struct box *)q).str);
}
vector<int> solve(int l, int r) {
  int i, m, j;
  vector<int> re(r - l + 2, -999999999);
  if (l == r) {
    re[0] = 0;
    re[1] = 0;
    return re;
  }
  for (m = l, i = l; i < r; i++)
    if (lcp[i] < lcp[m]) m = i;
  vector<int> veca = solve(l, m);
  vector<int> vecb = solve(m + 1, r);
  for (i = 0; i < veca.size(); i++)
    for (j = 0; j < vecb.size(); j++) {
      int tmp = re[i + j];
      if (veca[i] + vecb[j] + lcp[m] * i * j > tmp)
        re[i + j] = veca[i] + vecb[j] + lcp[m] * i * j;
    }
  return re;
}
int main() {
  int i, n, k, j;
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; i++) scanf("%s", s[i].str);
  qsort(s, n, sizeof(s[0]), comp);
  for (i = 0; i < n - 1; i++) {
    for (j = 0; s[i].str[j] != '\0' && s[i + 1].str[j] != '\0'; j++)
      if (s[i].str[j] != s[i + 1].str[j]) break;
    lcp[i] = j;
  }
  vector<int> vec = solve(0, n - 1);
  printf("%d\n", vec[k]);
}
