#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int h[maxn], f[maxn][maxn];
string s[maxn];
int n, k, tot;
int work(int l, int r) {
  if (l + 1 == r) return maxn - 1;
  int i, j, m, x, y, t = ++tot;
  m = min_element(h + l + 1, h + r) - h;
  x = work(l, m);
  y = work(m, r);
  for (i = 0; i <= m - l; ++i)
    for (j = 0; j <= r - m; ++j)
      f[t][i + j] = max(f[t][i + j], f[x][i] + f[y][j] + h[m] * i * j);
  return t;
}
int main() {
  int i, l, t;
  cin >> n >> k;
  for (i = 0; i < n; ++i) cin >> s[i];
  sort(s, s + n);
  for (i = 1; i < n; ++i) {
    t = min(s[i].length(), s[i - 1].length());
    for (l = 0; l < t && s[i][l] == s[i - 1][l]; ++l)
      ;
    h[i] = l;
  }
  cout << f[work(0, n)][k] << endl;
}
