#include <bits/stdc++.h>
using namespace std;
const int MAXN = 600;
const int INF = 1000000000;
int n, m, last;
int go[50005][26], sons[50005];
int d[50005][102];
int p[50005];
char s[MAXN];
void dfs(int u) {
  for (int i = 1; i <= m; i++) d[u][i] = -INF;
  for (int i = 1; i <= sons[u]; i++) d[u][i] = 0;
  for (int i = 0; i < 26; i++)
    if (go[u][i]) dfs(go[u][i]);
  if (u)
    for (int j = m, i; j >= 0; j--)
      if (d[p[u]][j] != -INF)
        for (i = 1; i <= m - j; i++) {
          if (d[u][i] != -INF) {
            d[p[u]][j + i] =
                max(d[p[u]][j + i], d[p[u]][j] + d[u][i] + i * (i - 1) / 2);
          }
        }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0, k; i < n; i++) {
    scanf("%s", s);
    k = 0;
    for (int j = 0; s[j]; j++) {
      if (!go[k][s[j] - 'a']) go[k][s[j] - 'a'] = ++last, p[last] = k;
      k = go[k][s[j] - 'a'];
    }
    sons[k]++;
  }
  dfs(0);
  printf("%d\n", d[0][m]);
  return 0;
}
