#include <bits/stdc++.h>
using namespace std;
char ch[2005][2505];
int c[2005], n, k, len[2005], h[2005];
bool cmp(const int a, const int b) {
  int u = a, v = b;
  int l = min(len[u], len[v]);
  for (int i = 0; i < l; i++)
    if (ch[u][i] != ch[v][i]) return ch[u][i] < ch[v][i];
  return len[u] < len[v];
}
int tmp[2005];
void Merge_sort(int l, int r) {
  if (l >= r) return;
  int mid = (l + r) >> 1, i = l, j = mid + 1, k = l;
  Merge_sort(l, mid), Merge_sort(mid + 1, r);
  for (; i <= mid && j <= r;) {
    if (cmp(c[i], c[j]))
      tmp[k++] = c[i++];
    else
      tmp[k++] = c[j++];
  }
  for (; i <= mid;) tmp[k++] = c[i++];
  for (; j <= r;) tmp[k++] = c[j++];
  for (int i = l; i <= r; i++) c[i] = tmp[i];
}
vector<int> ser(int l, int r) {
  vector<int> ret;
  ret.resize(min(r - l + 3, k + 1));
  if (l > r) return ret;
  int Min = 0x3f3f3f3f, Minloc;
  for (int i = l; i <= r; i++)
    if (h[i] < Min) {
      Min = h[i];
      Minloc = i;
    }
  vector<int> A = ser(l, Minloc - 1), B = ser(Minloc + 1, r);
  for (int i = 0, siz = A.size(); i < siz; i++)
    for (int j = 0, siz2 = B.size(); j < siz2 && i + j <= k; j++)
      ret[i + j] = max(ret[i + j], A[i] + B[j] + i * j * Min);
  return ret;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%s", ch[i]);
    c[i] = i, len[i] = strlen(ch[i]);
  }
  Merge_sort(1, n);
  for (int i = 1; i < n; i++)
    for (h[i] = 0; h[i] < len[c[i]] && h[i] < len[c[i + 1]] &&
                   ch[c[i]][h[i]] == ch[c[i + 1]][h[i]];
         h[i]++)
      ;
  vector<int> ans = ser(1, n - 1);
  printf("%d\n", ans[k]);
}
