#include <bits/stdc++.h>
using namespace std;
int tot, dp[2005][2005], h[2005], n, k;
string str[2005];
int calc(int l, int r) {
  if (l == r) return n;
  int m = min_element(h + l, h + r) - h;
  int x = calc(l, m), y = calc(m + 1, r), res = tot++;
  for (int i = 0; i <= m - l + 1; i++) {
    for (int j = 0; j <= r - m; j++)
      dp[res][i + j] = max(dp[res][i + j], dp[x][i] + dp[y][j] + h[m] * i * j);
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> str[i];
  sort(str, str + n);
  for (int i = 0; i < n - 1; i++) {
    while (h[i] < str[i].size() && h[i] < str[i + 1].size() &&
           str[i][h[i]] == str[i + 1][h[i]])
      h[i]++;
  }
  cout << dp[calc(0, n - 1)][k] << endl;
  return 0;
}
