#include <bits/stdc++.h>
using namespace std;
string a[2005];
char s[2005];
int f[2005 * 2][2005], h[2005], n, m, k;
void dp(int l, int r, int x) {
  if (l >= r) return;
  int L = ++m, R = ++m, mid = l;
  for (int i = l; i < r; i++)
    if (h[i] < h[mid]) mid = i;
  dp(l, mid, L), dp(mid + 1, r, R);
  for (int i = 0; i < mid - l + 2; i++)
    for (int j = 0; j < r - mid + 1; j++)
      if (i + j <= k)
        f[x][i + j] = max(f[x][i + j], h[mid] * i * j + f[L][i] + f[R][j]);
}
int main() {
  scanf("%d%d ", &n, &k);
  for (int i = 0; i < n; i++) gets(s), a[i] = s;
  sort(a, a + n);
  for (int i = 0; i < n - 1; i++) {
    h[i] = min(a[i].size(), a[i + 1].size());
    for (int j = 0; j < h[i]; j++)
      if (a[i][j] != a[i + 1][j]) h[i] = j;
  }
  dp(0, n - 1, 0);
  printf("%d\n", f[0][k]);
  return 0;
}
