#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10, MN = 2e3 + 10;
int dp[MN << 2][MN];
int n, k;
int L[MN << 2], R[MN << 2], Now = 1;
string s[MN];
int mn[MN][MN], arr[MN];
void solve(int id, int b, int e) {
  if (e <= b) return;
  int mid = mn[b][e];
  if (!L[id]) L[id] = Now++;
  if (!R[id]) R[id] = Now++;
  solve(L[id], b, mid), solve(R[id], mid + 1, e);
  for (int l = 0; l < k && l <= mid - b; ++l)
    for (int r = 0; r < k - l && r <= e - mid - 1; ++r) {
      dp[id][l + r + 1] =
          max(dp[id][l + r + 1],
              dp[L[id]][l] + dp[R[id]][r] + arr[mid] * (l * r + l + r + 1));
    }
  for (int l = 0; l <= k; ++l) {
    dp[id][l] = max(dp[L[id]][l], dp[id][l]);
    dp[id][l] = max(dp[id][l], dp[R[id]][l]);
  }
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> s[i];
  sort(s, s + n);
  for (int i = 0; i < n - 1; ++i) {
    while (arr[i] < min(((int)(s[i]).size()), ((int)(s[i + 1]).size())) &&
           s[i][arr[i]] == s[i + 1][arr[i]])
      ++arr[i];
  }
  --n, --k;
  if (!k) return cout << "0\n", 0;
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j <= n; ++j) {
      if (j - i == 1)
        mn[i][j] = i;
      else {
        if (arr[j - 1] <= arr[mn[i][j - 1]])
          mn[i][j] = j - 1;
        else
          mn[i][j] = mn[i][j - 1];
      }
    }
  solve(0, 0, n);
  cout << dp[0][k] << '\n';
  return 0;
}
