#include <bits/stdc++.h>
const int N = 2514;
const int Q = (int)1e6;
int n, K, vque[Q], vfr, vbk, dp[N], lenth[N];
std::string str[N];
std::vector<int> vc[Q];
int get_node() {
  int res = vque[vfr++];
  if (vfr >= Q) vfr -= Q;
  return res;
}
void release(int a) {
  vc[a].clear();
  vque[vbk++] = a;
  if (vbk >= Q) vbk -= Q;
}
void uni(int m1, int m2, int idx, int d) {
  memset(dp, (0), sizeof(dp));
  for (int i = (0); i <= ((int)vc[m1].size() - 1); i++) {
    if (i > K) break;
    for (int j = (0); j <= ((int)vc[m2].size() - 1); j++) {
      if (i + j > K) break;
      dp[i + j] = std::max(dp[i + j], vc[m1][i] + vc[m2][j] + i * j * d);
    }
  }
  int ed = vc[m1].size() + vc[m2].size() - 2;
  if (ed > K) ed = K;
  for (int i = (0); i <= (ed); i++) {
    vc[idx].push_back(dp[i]);
  }
  release(m1);
  release(m2);
}
void dfs(int nL, int nR, int dep, int idx) {
  if (nL == nR) {
    vc[idx].push_back(0);
    vc[idx].push_back(0);
    return;
  }
  if (dep >= lenth[nL]) {
    int m1 = get_node();
    int m2 = get_node();
    vc[m1].push_back(0);
    vc[m1].push_back(0);
    dfs(nL + 1, nR, dep, m2);
    uni(m1, m2, idx, dep);
    return;
  }
  int sign = 1, m1, m2;
  for (int i = (nL); i <= (nR - 1); i++) {
    if (str[i][dep] != str[i + 1][dep]) {
      sign = 0;
      m1 = get_node();
      m2 = get_node();
      dfs(nL, i, dep, m1);
      dfs(i + 1, nR, dep, m2);
      uni(m1, m2, idx, dep);
      return;
    }
  }
  dfs(nL, nR, dep + 1, idx);
}
void solve() {
  for (int i = (0); i <= (n - 1); i++) {
    char s[514];
    scanf("%s", s);
    str[i] = std::string(s);
  }
  std::sort(str, str + n);
  for (int i = (0); i <= (n - 1); i++) lenth[i] = str[i].length();
  vfr = vbk = 0;
  for (int i = (0); i <= (Q - 1); i++) release(i);
  int st = get_node();
  dfs(0, n - 1, 0, st);
  printf("%d\n", vc[st][vc[st].size() - 1]);
}
int main() {
  while (~scanf("%d%d", &n, &K)) solve();
  return 0;
}
