#include <bits/stdc++.h>
using namespace std;
int n, k, f[2100][2100], h[2100], tot, i, l[2100], j;
string s[2100];
int dp(int l, int r) {
  if (l == r) return 0;
  int X = ++tot, i, j, mid = l + 1, x, y;
  for (i = l + 1; i <= r; ++i)
    if (h[i] < h[mid]) mid = i;
  x = dp(l, mid - 1);
  y = dp(mid, r);
  for (i = 0; i <= mid - l; ++i)
    for (j = 0; j <= r - mid + 1; ++j)
      f[X][i + j] = max(f[X][i + j], f[x][i] + f[y][j] + h[mid] * i * j);
  return X;
}
int main() {
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; ++i) cin >> s[i];
  sort(s + 1, s + n + 1);
  l[1] = s[1].length();
  for (i = 2; i <= n; ++i) {
    l[i] = s[i].length();
    for (j = 0; j < l[i - 1] && j < l[i] && s[i - 1][j] == s[i][j]; ++j)
      ;
    h[i] = j;
  }
  printf("%d\n", f[dp(1, n)][k]);
}
