#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000;
string second[maxn];
int n, k, lcp[maxn];
int getLcp(string second, string t) {
  int i;
  for (i = 0; i < second.size() && i < t.size(); ++i)
    if (second[i] != t[i]) break;
  return i;
}
vector<int> Calc(int l, int r) {
  if (r - l == 1) {
    vector<int> tmp(3, 0);
    tmp[2] = lcp[l];
    return tmp;
  }
  if (l == r) {
    vector<int> tmp(2, 0);
    return tmp;
  }
  int m = l;
  for (int i = l; i < r; ++i)
    if (lcp[i] < lcp[m]) m = i;
  vector<int> dp0 = Calc(l, m), dp1 = Calc(m + 1, r);
  vector<int> dp(r - l + 2, 0);
  for (int i = 0; i < dp0.size(); ++i)
    for (int j = 0; j < dp1.size(); ++j) {
      dp[i + j] = max(dp[i + j], dp0[i] + dp1[j] + i * j * lcp[m]);
    }
  return dp;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    char ss[600];
    scanf("%s", &ss);
    second[i] = ss;
  }
  sort(second, second + n);
  for (int i = 0; i < n - 1; ++i) lcp[i] = getLcp(second[i], second[i + 1]);
  vector<int> dp = Calc(0, n - 1);
  cout << dp[k] << endl;
  return 0;
}
