#include <bits/stdc++.h>
using namespace std;
int N, K;
int height[2010];
string S[2010];
vector<int> F[2010][2010];
void lcp() {
  memset(height, 0, sizeof(height));
  for (int i = 1; i < N; i++) {
    int pos = 0, l1 = S[i].length(), l2 = S[i + 1].length();
    for (; pos < l1 && pos < l2 && S[i][pos] == S[i + 1][pos]; pos++)
      ;
    height[i] = pos;
  }
}
vector<int> solve(int l, int r) {
  if (l == r) {
    vector<int> R(2, 0);
    return R;
  }
  int mh = -1, mid;
  for (int i = l; i < r; i++)
    if (mh == -1 || mh > height[i]) mh = height[i], mid = i;
  vector<int> ll = solve(l, mid);
  vector<int> rr = solve(mid + 1, r);
  vector<int> R(r - l + 2, 0);
  for (int i = 0; i <= mid - l + 1; i++)
    for (int j = 0; j <= r - mid; j++)
      if (i + j <= K) R[i + j] = max(R[i + j], ll[i] + rr[j] + i * j * mh);
  return R;
}
int main() {
  cin >> N >> K;
  for (int i = 1; i <= N; i++) cin >> S[i];
  sort(S + 1, S + N + 1);
  lcp();
  vector<int> R = solve(1, N);
  cout << R[K] << endl;
  return 0;
}
