#include <bits/stdc++.h>
using namespace std;
int t, i, j, xx, n, k;
string a[2005];
int f[2005][2005], h[2005], l[2005];
int dp(int l, int r) {
  int mi;
  if (l == r) return n + 1;
  int xx = 1e9;
  for (i = l + 1; i <= r; i++)
    if (h[i] < xx) xx = h[i], mi = i;
  int x = dp(l, mi - 1);
  int y = dp(mi, r);
  t++;
  for (int i = 0; i <= mi - l; i++)
    for (int j = 0; j <= r - mi + 1; j++) {
      f[t][i + j] = max(f[t][i + j], f[x][i] + f[y][j] + h[mi] * i * j);
    }
  return t;
}
int main() {
  scanf("%d%d ", &n, &k);
  for (i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (i = 1; i <= n; i++) l[i] = a[i].size();
  for (i = 2; i <= n; i++) {
    xx = -1;
    for (j = 0; j < min(l[i], l[i - 1]); j++)
      if (a[i][j] != a[i - 1][j]) {
        xx = j;
        break;
      }
    if (xx == -1) xx = min(l[i], l[i - 1]);
    h[i] = xx;
  }
  cout << f[dp(1, n)][k];
}
