#include <bits/stdc++.h>
using namespace std;
const int MAX = 2000;
string s[MAX + 10];
int a[MAX + 10];
int n, k;
vector<long long> F(int s, int e) {
  if (s == e) return vector<long long>(2, 0);
  int mnp = s;
  for (int i = s + 1; i < e; i++)
    if (a[i] < a[mnp]) mnp = i;
  vector<long long> v1 = F(s, mnp);
  vector<long long> v2 = F(mnp + 1, e);
  vector<long long> ret;
  ret.resize(e - s + 1 + 1);
  for (int i = 0; i <= (e - s + 1); i++)
    for (int j = 0; j <= i && j < (int)v1.size(); j++)
      if (i - j < (int)v2.size())
        ret[i] = max(ret[i], v1[j] + v2[i - j] + j * (i - j) * a[mnp]);
  return ret;
}
int main() {
  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 = 0; i < n - 1; i++)
    a[i] = mismatch(s[i].begin(), s[i].end(), s[i + 1].begin()).first -
           s[i].begin();
  vector<long long> ret = F(0, n - 1);
  long long mx = 0;
  for (int i = 0; i < (int)ret.size() && i <= k; i++) mx = max(mx, ret[i]);
  cout << mx << endl;
  return 0;
}
