#include <bits/stdc++.h>
using namespace std;
const int maxN = 110, maxL = 510;
int b[maxN * maxL][26], v[maxN * maxL], h = 1;
int d[maxN * maxL][maxN], p[maxN], l, i, n;
char s[maxL];
void add() {
  int i, t;
  for (v[0]++, t = 0, i = 0; s[i]; t = b[t][s[i] - 'a'], v[t]++, i++)
    if (!b[t][s[i] - 'a']) b[t][s[i] - 'a'] = h++;
}
void dfs(int i) {
  int j, k, t, s, f;
  for (j = 0; j < 26; j++)
    if (b[i][j]) dfs(b[i][j]);
  for (s = 0, j = 0; j < 26; j++)
    if (b[i][j]) {
      t = b[i][j];
      for (k = 0; k <= l && k <= s; k++)
        for (f = 0; k + f <= l && f <= v[t]; f++)
          if (d[i][k] + d[t][f] + f * (f - 1) / 2 > p[k + f])
            p[k + f] = d[i][k] + d[t][f] + f * (f - 1) / 2;
      s += v[t];
      for (k = 0; k <= l && k <= s; d[i][k] = p[k], p[k] = 0, k++)
        ;
    }
  for (s++; s <= l && s <= v[i]; d[i][s] = d[i][s - 1], s++)
    ;
}
int main() {
  for (scanf("%d%d", &n, &l), i = 0; i < n; scanf("%s", s), add(), i++)
    ;
  dfs(0);
  printf("%d\n", d[0][l]);
  return 0;
}
