#include <bits/stdc++.h>
using namespace std;
char *s[2010];
int cmp(char *a, char *b) {
  a++;
  b++;
  while ((*a) && (*b) && (*a) == (*b)) a++, b++;
  if ((*a) && (*b)) return (*a) < (*b);
  if (!(*a) && !(*b)) return 0;
  return !(*a);
}
int lcp(char *a, char *b) {
  int r = 0;
  while ((*a) && (*b) && (*a) == (*b)) a++, b++, r++;
  return r;
}
int *dp[2010][2010];
int h[2010];
int dfs(int l, int r, int m) {
  if (!m || l >= r || m > r - l + 1) return 0;
  if (dp[l][r] == NULL) {
    dp[l][r] = new int[2010];
    for (int i = (0); i <= (2010 - 1); i++) dp[l][r][i] = -1;
  }
  if (dp[l][r][m] != -1) return dp[l][r][m];
  int minv = 10000, minvi;
  for (int i = (l + 1); i <= (r); i++)
    if (h[i] < minv) minv = h[i], minvi = i;
  int res = 0;
  for (int i = (0); i <= (m); i++)
    res = max(res,
              i * (m - i) * minv + dfs(l, minvi - 1, i) + dfs(minvi, r, m - i));
  dp[l][r][m] = res;
  return res;
}
void lemon() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (n); i++) {
    s[i] = new char[510];
    scanf("%s", s[i] + 1);
  }
  sort(s + 1, s + n + 1, cmp);
  for (int i = (2); i <= (n); i++) h[i] = lcp(s[i] + 1, s[i - 1] + 1);
  memset(dp, 0, sizeof dp);
  printf("%d\n", dfs(1, n, m));
}
int main() {
  ios::sync_with_stdio(true);
  lemon();
  return 0;
}
