#include <bits/stdc++.h>
using namespace std;
int n, m, c[2111], x[2111][2111], cx(1);
string s[2111];
int *dp(int l, int r) {
  if (l == r) return x[0];
  int *f = x[cx++], k = 0;
  for (int i = l; i < r; ++i)
    if (c[k] > c[i]) k = i;
  int *g = dp(l, k), *h = dp(k + 1, r);
  for (int i = 0; i <= min(k - l + 1, m); ++i)
    for (int j = 0; j <= min(r - k, m - i); ++j)
      if (f[i + j] < g[i] + h[j] + i * j * c[k])
        f[i + j] = g[i] + h[j] + i * j * c[k];
  return f;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> s[i];
  c[0] = 0x7fffffff;
  sort(s + 1, s + n + 1);
  unsigned int j;
  for (int i = 1; i <= n; c[i++] = j)
    for (j = 0; j < s[i].length() && s[i][j] == s[i + 1][j]; ++j)
      ;
  cout << dp(1, n)[m] << endl;
  return 0;
}
