#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = false;
  while (!isdigit(c)) {
    if (c == '-') flag = true;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
  if (flag) x = -x;
}
using namespace std;
template <typename T>
inline void MAX(T &a, T b) {
  if (a < b) a = b;
}
int n, K;
int trie[1001000][26];
int blong[1001000];
int imp[2022], itot, ttot;
int cnt[1001000];
inline void Readin() {
  static char s[567];
  scanf("%s", s + 1);
  int len = strlen(s + 1);
  int p = 0;
  for (int i = 1; i <= len; ++i) {
    int c = s[i] - 'a';
    if (!trie[p][c]) trie[p][c] = ++ttot;
    p = trie[p][c];
  }
  if (!blong[p])
    imp[++itot] = p, blong[p] = itot, cnt[itot] = 1;
  else
    ++cnt[blong[p]];
}
struct edge {
  int nxt, to;
  edge() {}
  edge(int jzp, int zzz) { nxt = jzp, to = zzz; }
} e[2022 << 2];
int head[2022 << 1], ecnt;
int dep[2022 << 1], fa[2022 << 1];
inline void addedge(int from, int to) {
  e[++ecnt] = edge(head[from], to);
  head[from] = ecnt;
}
void dfs_virtual(int cur, int lst, int nwd) {
  int ct = 0;
  for (int c = 0; c < 26; ++c) ct += (trie[cur][c] > 0);
  if (cur == 0) ct = 26;
  if (ct > 1 || blong[cur]) {
    if (!blong[cur]) blong[cur] = ++ttot;
    dep[blong[cur]] = nwd;
    fa[blong[cur]] = lst;
    if (lst) addedge(lst, blong[cur]);
    lst = blong[cur];
  }
  for (int c = 0; c < 26; ++c)
    if (trie[cur][c]) {
      dfs_virtual(trie[cur][c], lst, nwd + 1);
    }
}
long long f[2022 << 1][2022];
int siz[2022 << 1];
inline long long get_C2(long long n) { return n * (n - 1) >> 1; }
void dfs_ans(int cur) {
  siz[cur] = cnt[cur];
  for (int i = head[cur]; i; i = e[i].nxt) {
    int to = e[i].to;
    dfs_ans(to);
    for (int j = siz[cur]; ~j; --j) {
      for (int k = 1; k <= siz[to]; ++k) {
        MAX(f[cur][j + k], f[cur][j] + f[to][k]);
      }
    }
    siz[cur] += siz[to];
  }
  for (int i = 0; i <= siz[cur]; ++i) {
    f[cur][i] = f[cur][i] + 1ll * get_C2(i) * (dep[cur] - dep[fa[cur]]);
  }
}
int main() {
  read(n), read(K);
  for (int i = 1; i <= n; ++i) Readin();
  ttot = itot;
  dfs_virtual(0, 0, 0);
  dfs_ans(itot + 1);
  long long res = 0;
  for (int i = 0; i <= K; ++i) MAX(res, f[itot + 1][i]);
  printf("%lld\n", res);
  return 0;
}
