#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
int n, k, m;
string s[maxn];
int a[maxn], b[maxn];
int f[maxn][maxn];
int *sol(int l, int r) {
  if (l >= r) return f[0];
  int *F = f[++m], i, j, p;
  for (p = i = l; i < r; ++i)
    if (b[i] < b[p]) p = i;
  int *L = sol(l, p), *R = sol(p + 1, r);
  for (i = 0; i <= p - l + 1; ++i)
    for (j = 0; j <= r - p; ++j)
      F[i + j] = max(F[i + j], L[i] + R[j] + b[p] * i * j);
  return F;
}
int main() {
  int i, j;
  scanf("%d%d\n", &n, &k);
  for (i = 0; i < n; ++i) getline(cin, s[i]);
  sort(s, s + n);
  for (i = 0; i < n; ++i) a[i] = s[i].length();
  for (i = 1; i < n; b[i++] = j)
    for (j = 0; j < a[i - 1] && j < a[i] && s[i - 1][j] == s[i][j]; ++j)
      ;
  cout << sol(1, n)[k];
  return 0;
}
