#include <bits/stdc++.h>
using namespace std;
const int MX = 2005;
int lcp[MX];
int n;
int cnt = 0;
int dp[2 * MX][MX];
int calc(int L, int R) {
  int cur = cnt++;
  if (L == R) return cur;
  int ii = L;
  for (int i = L + 1; i < R; i++) {
    if (lcp[i] < lcp[ii]) ii = i;
  }
  int a = calc(L, ii), b = calc(ii + 1, R);
  for (int lk = 0; lk <= ii - L + 1; lk++) {
    for (int rk = 0; rk <= R - ii; rk++) {
      int tmp = dp[a][lk] + dp[b][rk] + lcp[ii] * lk * rk;
      dp[cur][lk + rk] = max(dp[cur][lk + rk], tmp);
    }
  }
  return cur;
}
string s[MX];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> s[i];
  sort(s, s + n);
  for (int i = 0; i + 1 < n; i++) {
    while (lcp[i] < (int)s[i].size() && lcp[i] < (int)s[i + 1].size() &&
           s[i][lcp[i]] == s[i + 1][lcp[i]]) {
      lcp[i]++;
    }
  }
  calc(0, n - 1);
  printf("%d\n", dp[0][k]);
}
