#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chkmin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline void chkmax(T &a, T b) {
  if (a < b) a = b;
}
char word[2100][510];
int lcp[2100], id[2100][2100], M, mid[2100][2100];
int dp[4100][2100];
int cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
void find(int l, int r) {
  id[l][r] = M++;
  if (r > l + 1) {
    find(l, mid[l][r]);
    find(mid[l][r], r);
  }
}
void calc(int t, int l, int r) {
  if (r - l == 1) return;
  int i, j, tmp, m = mid[l][r], t1 = id[l][m], t2 = id[m][r];
  calc(t1, l, m);
  calc(t2, m, r);
  for (i = 0; i <= m - l; i++)
    for (j = 0; j <= r - m; j++) {
      tmp = dp[t1][i] + dp[t2][j] + i * j * lcp[m - 1];
      chkmax(dp[t][i + j], tmp);
    }
}
int main() {
  int N, K, i, j, k, ans, sum;
  scanf("%d%d", &N, &K);
  for (i = 0; i < N; i++) scanf("%s", word[i]);
  qsort(word, N, sizeof(word[0]), cmp);
  ans = 0;
  for (i = 0; i < N - 1; i++) {
    for (j = 0; word[i][j] && word[i + 1][j] && word[i][j] == word[i + 1][j];
         j++)
      ;
    lcp[i] = j;
  }
  for (i = 0; i < N - 1; i++) {
    mid[i][i + 2] = i + 1;
    for (j = i + 3; j <= N; j++) {
      mid[i][j] = mid[i][j - 1];
      if (lcp[mid[i][j] - 1] > lcp[j - 2]) mid[i][j] = j - 1;
    }
  }
  find(0, N);
  calc(0, 0, N);
  printf("%d\n", dp[0][K]);
  return 0;
}
