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