#include <bits/stdc++.h>
using namespace std;
int n, k, lcp[2005];
string s[2005];
int get(string s1, string s2) {
  int got = 0;
  for (int i = 0; i < min(s1.length(), s2.length()); i++) {
    if (s1[i] != s2[i]) break;
    got++;
  }
  return got;
}
vector<int> solve(int l, int r) {
  if (r <= l) return vector<int>(k + 1, 0);
  int mini = 10000000;
  int pos = -1;
  for (int i = l; i < r; i++) {
    if (lcp[i] < mini) {
      mini = lcp[i];
      pos = i;
    }
  }
  vector<int> lft = solve(l, pos);
  vector<int> rght = solve(pos + 1, r);
  vector<int> ans(k + 1, 0);
  for (int i = 0; i <= min(k, pos - l + 1); i++) {
    for (int j = 0; j <= r - pos && i + j <= k; j++)
      ans[i + j] = max(ans[i + j], lft[i] + rght[j] + mini * i * j);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  int i;
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> s[i];
  sort(s + 1, s + n + 1);
  for (i = 1; i < n; i++) lcp[i] = get(s[i], s[i + 1]);
  vector<int> ans = solve(1, n);
  cout << ans[k];
  return 0;
}
