#include <bits/stdc++.h>
using namespace std;
int n, k, a[1000005];
string s[1000005];
int yap(string s, string ss) {
  int u = s.length();
  int uu = ss.length();
  int say = 0;
  for (int i = 0; i < min(u, uu); i++)
    if (s[i] == ss[i])
      say++;
    else
      break;
  return say;
}
int minbul(int bas, int son) {
  pair<int, int> mn = make_pair(a[bas], bas);
  for (int i = bas + 1; i <= son; i++) mn = min(mn, make_pair(a[i], i));
  return mn.second;
}
vector<int> f(int bas, int son) {
  int u = son - bas + 1;
  vector<int> don(min(k + 1, u + 1), 0);
  if (u <= 1) return don;
  int top = 0;
  int orta = minbul(bas, son - 1);
  vector<int> sol = f(bas, orta);
  vector<int> sag = f(orta + 1, son);
  int ssol = sol.size();
  int ssag = sag.size();
  for (int i = 1; i <= min(u, k); i++)
    for (int j = 0; j <= min(i, ssol - 1); j++)
      if (i - j < ssag) {
        don[i] = max(don[i], sol[j] + sag[i - j] + j * (i - j) * a[orta]);
      }
  return don;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) cin >> s[i];
  sort(s + 1, s + n + 1);
  for (int i = 1; i <= n - 1; i++) a[i] = yap(s[i], s[i + 1]);
  printf("%d\n", f(1, n).back());
  return 0;
}
