#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
string s[MAXN + 10];
int f[MAXN + 10][MAXN + 10];
int nodeN;
int lcp[MAXN + 10];
int fun(int l, int r) {
  int id = nodeN++;
  if (l == r) return id;
  int split = l;
  for (int i = l; i < r; i++)
    if (lcp[i] < lcp[split]) split = i;
  int left = fun(l, split);
  int right = fun(split + 1, r);
  for (int lTake = 0; lTake <= split - l + 1; lTake++)
    for (int rTake = 0; rTake <= r - split; rTake++)
      f[id][lTake + rTake] =
          max(f[id][lTake + rTake],
              f[left][lTake] + f[right][rTake] + lcp[split] * lTake * rTake);
  return id;
}
int n, k;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    char tmp[510];
    scanf("%s", tmp);
    s[i] = tmp;
  }
  sort(s + 1, s + 1 + n);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < min(s[i].size(), s[i + 1].size()); j++)
      if (s[i][j] != s[i + 1][j]) {
        lcp[i] = j;
        goto NextLoop;
      }
    lcp[i] = min(s[i].size(), s[i + 1].size());
  NextLoop:;
  }
  cout << f[fun(1, n)][k] << endl;
}
