#include <bits/stdc++.h>
using namespace std;
string s[2010];
int n, K, lcp[2010], dp[4010][2010], idcnt;
void solve(int &p, int l, int r) {
  p = ++idcnt;
  if (l == r) {
    fill(dp[p], dp[p] + K + 1, -1e9);
    dp[p][0] = dp[p][1] = 0;
    return;
  }
  int mid = l;
  for (int i = l + 1; i < r; i++)
    if (lcp[i] < lcp[mid]) mid = i;
  int lc, rc;
  solve(lc, l, mid);
  solve(rc, mid + 1, r);
  for (int L = 0; L <= mid - l + 1; L++) {
    for (int R = 0; R <= r - mid; R++) {
      dp[p][L + R] =
          max(dp[p][L + R], dp[lc][L] + dp[rc][R] + lcp[mid] * L * R);
    }
  }
}
int main() {
  scanf("%d%d", &n, &K);
  for (int i = 1; i <= n; i++) cin >> s[i];
  sort(s + 1, s + n + 1);
  for (int i = 1; i < n; i++) {
    lcp[i] = -1;
    for (int j = 0; j < s[i].size() && j < s[i + 1].size(); j++) {
      if (s[i][j] != s[i + 1][j]) {
        lcp[i] = j;
        break;
      }
    }
    if (lcp[i] == -1) lcp[i] = min(s[i].size(), s[i + 1].size());
  }
  int rt;
  solve(rt, 1, n);
  printf("%d\n", dp[rt][K]);
  return 0;
}
