#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
int a, b, c, d, i, j, n, m, k;
int nx[50002][26], sib[50002], pr[50002], fir[50002];
int cnt[50002], en[50002];
char str[502];
int dp[50001][101];
int dfs(int v) {
  for (int _n((26) - 1), i(0); i <= _n; i++) {
    if (nx[v][i] != -1) cnt[v] += dfs(nx[v][i]);
  }
  return cnt[v];
}
int rec(int v, int c) {
  if (c < 0) return -1000000000;
  if (v == -1 && !c) return 0;
  if (v == -1) return -1000000000;
  if (!c) return 0;
  if (dp[v][c] != -1) return dp[v][c];
  int ans = 0, fr = cnt[v] - en[v];
  for (int i = (min(cnt[v], c)), _b = (0); i >= _b; i--) {
    int lf = c - i;
    if (lf && sib[v] == -1) break;
    ans = max(ans, i * (i - 1) / 2 + rec(fir[v], min(fr, i)) + rec(sib[v], lf));
  }
  return dp[v][c] = ans;
}
int main() {
  memset(nx, -1, sizeof(nx));
  pr[0] = -1;
  k = 1;
  int tot = 0;
  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, -1, sizeof(dp));
  int ans = rec(fir[0], tot);
  printf("%d\n", ans);
}
