#include <bits/stdc++.h>
using namespace std;
long long cnt, n, m, mn, b[5001], f[5001][2001];
string a[2001];
char s[2001];
void dp(long long l, long long r, long long now) {
  long long i, mid = l, j, l1, r1;
  if (l >= r) return;
  l1 = ++cnt;
  r1 = ++cnt;
  for (i = l + 1; i < r; i++)
    if (b[i] < b[mid]) mid = i;
  dp(l, mid, l1);
  dp(mid + 1, r, r1);
  for (i = 0; i <= mid - l + 1; i++)
    for (j = 0; j <= r - mid; j++)
      if (i + j <= m)
        f[now][i + j] =
            max(f[now][i + j], f[l1][i] + f[r1][j] + i * j * b[mid]);
}
int main() {
  long long i, j, l, r;
  scanf("%lld%lld", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%s", s);
    a[i] = s;
  }
  sort(a + 1, a + n + 1);
  for (i = 1; i < n; i++) {
    l = a[i].size();
    r = a[i + 1].size();
    mn = min(l, r);
    b[i] = mn;
    for (j = 0; j < mn; j++)
      if (a[i][j] != a[i + 1][j]) {
        b[i] = j;
        break;
      }
  }
  dp(1, n, 0);
  printf("%lld", f[0][m]);
}
