#include <bits/stdc++.h>
using namespace std;
const int N = 6000;
int dp[N][N], len[N], dep[N], sz[N], n, k, val[N];
char S[N * 300];
char *s[N];
struct Edge {
  int L, len;
  int to;
  Edge(int L = 0, int len = 0, int to = 0) : L(L), len(len), to(to) {}
} d[N][26];
inline int idx(int c) { return c - 'a'; }
void dfs(int x) {
  sz[x] = val[x];
  for (int i = 0; i <= sz[x]; i++) dp[x][i] = dep[x] * i * (i - 1) / 2;
  for (int i = 0; i < 26; i++)
    if (d[x][i].to) {
      int u = d[x][i].to;
      dep[u] = dep[x] + d[x][i].len;
      dfs(u);
      sz[x] += sz[u];
      for (int i = sz[x]; i >= 0; i--) {
        int xx = 0;
        for (int j = 0; j <= sz[u] && j <= i; j++)
          xx = max(xx, dp[x][i - j] + dp[u][j] + j * (i - j) * dep[x]);
        dp[x][i] = xx;
      }
    }
}
int xb;
int main() {
  scanf("%d%d", &n, &k);
  s[0] = S;
  xb = 1;
  for (int i = 1; i <= n; i++) {
    s[i] = s[i - 1] + len[i - 1];
    scanf("%s", s[i]);
    len[i] = strlen(s[i]);
    int q = 1;
    for (int j = 0; j < len[i];) {
      int c = idx(s[i][j]);
      if (d[q][c].to) {
        for (int k = 0; k < d[q][c].len && j + k <= len[i]; k++)
          if (s[i][j + k] != S[d[q][c].L + k]) {
            int p = d[q][c].to;
            d[q][c].to = ++xb;
            int nq = xb;
            if (j + k < len[i]) d[nq][idx(s[i][j + k])].to = ++xb;
            d[nq][idx(S[d[q][c].L + k])].to = p;
            if (j + k < len[i]) {
              d[nq][idx(s[i][j + k])].L = (&s[i][j + k]) - S;
              d[nq][idx(s[i][j + k])].len = len[i] - j - k;
            }
            d[nq][idx(S[d[q][c].L + k])].L = d[q][c].L + k;
            d[nq][idx(S[d[q][c].L + k])].len = d[q][c].len - k;
            d[q][c].len = k;
            break;
          }
      } else {
        d[q][c].L = (&s[i][j]) - S;
        d[q][c].len = len[i] - j;
        d[q][c].to = ++xb;
      }
      j += d[q][c].len;
      q = d[q][c].to;
    }
    val[q]++;
  }
  dfs(1);
  printf("%d\n", dp[1][k]);
  return 0;
}
