#include <bits/stdc++.h>
using namespace std;
char s[2005][505];
int c[2005], len[2005], f[2005][2005], tot = 0;
bool cmp(int a, int b) { return strcmp(s[a], s[b]) == 1; }
int dfs(int l, int r) {
  if (r == l) return 0;
  int mid = min_element(len + l + 1, len + r + 1) - len;
  int x = dfs(l, mid - 1), y = dfs(mid, r);
  int q = ++tot;
  for (int i = 0; i <= mid - l; i++)
    for (int j = 0; j <= r - mid + 1; j++)
      f[q][i + j] = max(f[q][i + j], f[x][i] + f[y][j] + len[mid] * i * j);
  return q;
}
int main() {
  int n, k, i, res, ans;
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; i++) scanf("%s", s + i), c[i] = i;
  sort(c, c + n, cmp);
  for (i = 1; i < n; i++)
    for (len[i] = 0;
         s[c[i - 1]][len[i]] && s[c[i - 1]][len[i]] == s[c[i]][len[i]];
         len[i]++)
      ;
  memset(f, 0, sizeof f);
  printf("%d\n", f[dfs(0, n - 1)][k]);
  return 0;
}
