#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int sum = 0, w[N], f[N * 2][N];
string s[N];
bool compare(string a, string b) { return (a < b); }
int min(int a, int b) { return (a < b ? a : b); }
int work(int l, int r) {
  int d = ++sum;
  if (l < r) {
    int i, j, left, right, b = l;
    for (i = l + 1; i < r; i++)
      if (w[i] < w[b]) b = i;
    left = work(l, b);
    right = work(b + 1, r);
    for (i = 0; i <= b + 1 - l; i++)
      for (j = 0; j <= r - b; j++)
        if (f[d][i + j] < f[left][i] + f[right][j] + w[b] * i * j)
          f[d][i + j] = f[left][i] + f[right][j] + w[b] * i * j;
  }
  return (d);
}
int main() {
  memset(f, 0, sizeof(f));
  int n, k, i, j, temp;
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> s[i];
  sort(s + 1, s + n + 1, compare);
  for (i = 1; i < n; i++) {
    temp = min(s[i].size(), s[i + 1].size());
    w[i] = temp;
    for (j = 0; j < temp; j++)
      if (s[i][j] != s[i + 1][j]) {
        w[i] = j;
        break;
      }
  }
  work(1, n);
  cout << f[1][k];
  return (0);
}
