#include <bits/stdc++.h>
using namespace std;
struct node {
  int next, to;
} w[4001];
struct trie {
  int ch[26];
} t[1000001];
int f[4001][2001], cnt, head[4001], num;
int val[1000001], n, m, tot, sz[1000001];
int deep[4001], pc[4001];
char a[501];
inline void add(int x, int y) {
  w[++cnt].next = head[x];
  w[cnt].to = y;
  head[x] = cnt;
}
inline void insert() {
  int l = strlen(a + 1), rt = 1;
  for (int i = 1; i <= l; i++) {
    if (!t[rt].ch[a[i] - 'a']) t[rt].ch[a[i] - 'a'] = ++tot, sz[rt]++;
    rt = t[rt].ch[a[i] - 'a'];
  }
  val[rt]++;
}
void dfs(int x, int dep, int las) {
  if ((val[x] || sz[x] > 1) && (x != 1)) {
    num++;
    deep[num] = dep;
    pc[num] = val[x];
    add(las, num);
    las = num;
  }
  for (int i = 0; i < 26; i++)
    if (t[x].ch[i]) dfs(t[x].ch[i], dep + 1, las);
}
void dp(int x) {
  for (int i = 2; i <= pc[x]; i++) f[x][i] = i * (i - 1) / 2 * deep[x];
  for (int i = head[x]; i; i = w[i].next) {
    dp(w[i].to);
    pc[x] += pc[w[i].to];
    for (int j = min(pc[x], m); j; j--) {
      for (int k = min(j, pc[w[i].to]); k; k--)
        f[x][j] =
            max(f[x][j], f[x][j - k] + f[w[i].to][k] + (j - k) * k * deep[x]);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  tot = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%s", a + 1);
    insert();
  }
  num = 1;
  dfs(1, 0, 1);
  dp(1);
  printf("%d\n", f[1][m]);
  return 0;
}
