#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 2;
string str[2010];
int lp[2010];
int lcp(string a, string b) {
  int i;
  for (i = 0; i < a.size() && i < b.size(); i++)
    if (a[i] != b[i]) break;
  return i;
}
inline int max(int a, int b) { return a > b ? a : b; }
vector<int> solve(int l, int r) {
  int i, j;
  if (l + 1 == r) {
    vector<int> ret(2, 0);
    return ret;
  }
  int m = l;
  for (i = l; i < r - 1; i++)
    if (lp[i] < lp[m]) m = i;
  vector<int> a = solve(l, m + 1), b = solve(m + 1, r);
  vector<int> ret(r - l + 1, -inf);
  for (i = 0; i < a.size(); i++)
    for (j = 0; j < b.size(); j++)
      ret[i + j] = max(ret[i + j], a[i] + b[j] + lp[m] * i * j);
  return ret;
}
int main() {
  int n, m, i, j;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (i = 0; i < n; i++) cin >> str[i];
    sort(str, str + n);
    for (i = 0; i < n - 1; i++) lp[i] = lcp(str[i], str[i + 1]);
    vector<int> ret = solve(0, n);
    printf("%d\n", ret[m]);
  }
}
