#include <bits/stdc++.h>
using namespace std;
struct node {
  int f[26], qt, tf;
  node() {
    for (int(i) = (0); (i) < (26); (i)++) f[i] = 0;
    qt = tf = 0;
  }
} tr[1010100];
int ptr = 2;
void insere(int v, char* s) {
  if (!(*s))
    tr[v].qt++;
  else {
    int cur = (*s) - 'a';
    s++;
    if (!tr[v].f[cur]) tr[v].f[cur] = ptr++, tr[v].tf++;
    insere(tr[v].f[cur], s);
  }
}
vector<pair<int, int> > edges;
map<pair<int, int>, int> id;
vector<int> adj[10101], tam[10101];
int qt[10101], prox = 2;
int compress(int v, int c) {
  qt[c] = tr[v].qt;
  for (int(i) = (0); (i) < (26); (i)++)
    if (tr[v].f[i]) {
      int tt = 1;
      while (tr[tr[v].f[i]].tf == 1 && !tr[tr[v].f[i]].qt) {
        int id = -1;
        for (int(j) = (0); (j) < (26); (j)++)
          if (tr[tr[v].f[i]].f[j]) id = j;
        assert(id != -1);
        tr[v].f[i] = tr[tr[v].f[i]].f[id];
        tt++;
      }
      id[make_pair(c, ((int)(adj[c]).size()))] = ((int)(edges).size());
      edges.push_back(make_pair(c, ((int)(adj[c]).size())));
      adj[c].push_back(prox);
      tam[c].push_back(tt);
      qt[c] += compress(tr[v].f[i], prox++);
    }
  return qt[c];
}
long long pd[505][202];
char s[505];
long long solve(int p, int k) {
  if (p < 0) return 0;
  int v = edges[p].first, i = edges[p].second;
  long long& ret = pd[p][k];
  if (ret != -1) return ret;
  int pr = -1, u = adj[v][i];
  if (id.find(make_pair(v, i + 1)) != id.end()) pr = id[make_pair(v, i + 1)];
  ret = solve(pr, k);
  for (int(j) = (1); (j) < (min(k, qt[u]) + 1); (j)++) {
    int aux = -1;
    if (id.count(make_pair(u, 0))) aux = id[make_pair(u, 0)];
    ret = max(ret, solve(aux, j) + solve(pr, k - j) +
                       ((long long)j * (j - 1) / 2LL) * tam[v][i]);
  }
  return ret;
}
int main() {
  int n, k;
  memset(pd, -1, sizeof(pd));
  scanf("%d%d", &n, &k);
  for (int(i) = (0); (i) < (n); (i)++) {
    scanf("%s", s);
    insere(1, s);
  }
  compress(1, 1);
  puts("\n");
  printf("%lld\n", solve(0, k));
}
