#include <bits/stdc++.h>
using namespace std;
int N, K, i, tot;
string S[2005];
int H[2005], len[2005];
int f[4005][2005];
int Work(int l, int r) {
  int A, B, C, mid, i, j;
  A = tot++;
  if (l == r) return A;
  mid = l + 1;
  for (i = l + 2; i <= r; ++i)
    if (H[i] < H[mid]) mid = i;
  B = Work(l, mid - 1), C = Work(mid, r);
  for (i = 0; i <= mid - l; ++i)
    for (j = 0; j <= r - mid + 1 && i + j <= K; ++j)
      if (f[B][i] + f[C][j] + i * j * H[mid] > f[A][i + j])
        f[A][i + j] = f[B][i] + f[C][j] + i * j * H[mid];
  return A;
}
int main() {
  scanf("%d%d", &N, &K);
  for (i = 0; i < N; ++i) cin >> S[i];
  sort(S, S + N);
  for (i = 0; i < N; ++i) len[i] = S[i].length();
  for (i = 1; i < N; ++i)
    for (H[i] = 0;
         H[i] < len[i] && H[i] < len[i - 1] && S[i][H[i]] == S[i - 1][H[i]];
         ++H[i])
      ;
  printf("%d\n", f[Work(0, N - 1)][K]);
  return 0;
}
