#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
const int N = 1001002;
int a, b, c, d, i, j, n, m, k, tot, now, last, T;
int nx[N][26], sib[N], pr[N], fir[N];
int cnt[N], en[N], pcnt[2][N];
char str[502];
int num[N];
int dp[2][2002][2002], mlen[2][2002];
vector<int> lev[503];
int cfir[2002], ce[2002], ccnt[2002], csib[2002];
int dfs(int v, int h = 0) {
  lev[h].push_back(v);
  for (int _n((26) - 1), i(0); i <= _n; i++) {
    if (nx[v][i] != -1) cnt[v] += dfs(nx[v][i], h + 1);
  }
  return cnt[v];
}
inline int g(int v, int c) {
  if (c < 0) return -1000000000;
  if (v == -1 && !c) return 0;
  if (v == -1) return -1000000000;
  if (c > pcnt[last][v]) return -1000000000;
  if (c <= 1) return 0;
  if (c > mlen[last][v])
    return dp[last][v][mlen[last][v]];
  else
    return dp[last][v][c];
}
inline int f(int v, int c) {
  if (c < 0) return -1000000000;
  if (v == -1 && !c) return 0;
  if (v == -1) return -1000000000;
  if (c > pcnt[now][v]) return -1000000000;
  if (c <= 1) return 0;
  if (c > mlen[now][v])
    return dp[now][v][mlen[now][v]];
  else
    return dp[now][v][c];
}
int rec(int v, int c) {
  if (c < 0) return -1000000000;
  if (v == -1 && !c) return 0;
  if (v == -1) return -1000000000;
  if (c > pcnt[now][v]) return -1000000000;
  if (c <= 1) return 0;
  int ans = 0, fr = ccnt[v] - ce[v];
  for (int i = (min(ccnt[v], c)), _b = (0); i >= _b; i--) {
    int lf = c - i;
    if (lf && csib[v] == -1) break;
    int v2 = f(csib[v], lf);
    if (v2 < 0) continue;
    int v1 = g(cfir[v], min(fr, i));
    if (v1 < 0) continue;
    ans = max(ans, i * (i - 1) / 2 + v1 + v2);
  }
  return dp[now][v][c] = ans;
}
int main() {
  memset(nx, -1, sizeof(nx));
  pr[0] = -1;
  k = 1;
  scanf("%d%d", &n, &tot);
  for (int _n((n)-1), i(0); i <= _n; i++) {
    scanf("%s", str);
    m = (int)strlen(str);
    a = 0;
    for (int _n((m)-1), i(0); i <= _n; i++) {
      if (nx[a][str[i] - 'a'] == -1) {
        nx[a][str[i] - 'a'] = k++;
        pr[k - 1] = a;
      }
      a = nx[a][str[i] - 'a'];
    }
    ++cnt[a];
    ++en[a];
  }
  for (int _n((k)-1), i(0); i <= _n; i++) {
    fir[i] = -1;
    for (int j = (25), _b = (0); j >= _b; j--) {
      if (nx[i][j] == -1) continue;
      sib[nx[i][j]] = fir[i];
      fir[i] = nx[i][j];
    }
  }
  dfs(0);
  memset((dp), 0, sizeof(dp));
  now = 0, last = 1;
  memset(mlen, 63, sizeof(mlen));
  for (int h = (500), _b = (1); h >= _b; h--) {
    if (lev[h].empty()) continue;
    now ^= 1;
    last ^= 1;
    for (int _n(((int)((lev[h]).size())) - 1), i(0); i <= _n; i++)
      num[lev[h][i]] = i;
    T = (int)((lev[h]).size());
    for (int i = ((int)((lev[h]).size()) - 1), _b = (0); i >= _b; i--) {
      int v = lev[h][i];
      if (sib[v] == -1)
        pcnt[now][i] = cnt[v];
      else
        pcnt[now][i] = cnt[v] + pcnt[now][i + 1];
      if (fir[v] == -1)
        cfir[i] = -1;
      else
        cfir[i] = num[fir[v]];
      if (sib[v] == -1)
        csib[i] = -1;
      else
        csib[i] = i + 1;
      ce[i] = en[v];
      ccnt[i] = cnt[v];
    }
    for (int i = ((int)((lev[h]).size()) - 1), _b = (0); i >= _b; i--) {
      int v = lev[h][i];
      mlen[now][i] = 1000000000;
      for (int _n((tot + 1) - 1), j(0); j <= _n; j++) {
        if (j > pcnt[now][i]) break;
        rec(i, j);
        if (j >= 2 && dp[now][i][j] == dp[now][i][j - 1] &&
            dp[now][i][j] == dp[now][i][j - 2]) {
          mlen[now][i] = j;
          break;
        }
      }
    }
  }
  if (tot > mlen[now][0]) tot = mlen[now][0];
  int ans = dp[now][0][tot];
  printf("%d\n", ans);
}
