#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool Up(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool Down(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
inline int getus() {
  int tmp, c;
  while (tmp = fgetc(stdin), tmp < '0' || tmp > '9')
    ;
  tmp -= '0';
  while (c = fgetc(stdin), '0' <= c && c <= '9') tmp = tmp * 10 + c - '0';
  return tmp;
}
inline int getint() {
  int tmp, c, flag;
  while (flag = fgetc(stdin), flag != '-' && (flag < '0' || flag > '9'))
    ;
  if (flag == '-')
    tmp = 0;
  else
    tmp = flag - '0';
  while (c = fgetc(stdin), '0' <= c && c <= '9') tmp = tmp * 10 + c - '0';
  return flag == '-' ? -tmp : tmp;
}
int LCP(const string &a, const string &b) {
  int ans = 0;
  for (string::const_iterator ait(a.begin()), bit(b.begin());
       ait != a.end() && bit != b.end(); ++ait, ++bit)
    if (*ait == *bit)
      ++ans;
    else
      break;
  return ans;
}
int N, K, lcp[2048];
string s[2048];
vector<int> DP(int l, int r) {
  if (l == r) return vector<int>(2, 0);
  int cut = l;
  for (int i = l; i < r; ++i)
    if (lcp[i] < lcp[cut]) cut = i;
  vector<int> res(r - l + 2, -1000000000);
  vector<int> L(DP(l, cut)), R(DP(cut + 1, r));
  for (int i = 0; i < L.size(); ++i)
    for (int j = 0; j < R.size(); ++j)
      Up(res[i + j], L[i] + R[j] + lcp[cut] * i * j);
  return res;
}
void Work() {
  vector<int> ans(DP(0, N - 1));
  cout << ans[K] << endl;
}
void Init() {
  ios::sync_with_stdio(false);
  cin >> N >> K;
  for (int i = (0); i < (N); ++i) cin >> s[i];
  sort(s, s + N);
  for (int i = (1); i < (N); ++i) lcp[i - 1] = LCP(s[i - 1], s[i]);
}
int main() {
  Init();
  Work();
  return 0;
}
