#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 10, inf = 1000000000;
int n, k, com[maxn], mn[maxn][maxn], dp[2 * maxn][maxn], ind[maxn][maxn], u = 1;
string s[maxn];
void go(int l, int r) {
  if (l == r) return;
  ind[l][r] = u++;
  int pos = l;
  for (int i = l; i < r; i++)
    if (com[i] < com[pos]) pos = i;
  mn[l][r] = pos;
  go(l, pos);
  go(pos + 1, r);
}
void solve(int l, int r) {
  if (l == r) return;
  int id = ind[l][r];
  int pos = mn[l][r];
  solve(l, pos);
  solve(pos + 1, r);
  int id1 = ind[l][pos];
  int id2 = ind[pos + 1][r];
  for (int i = 0; i <= pos - l + 1; i++)
    for (int j = 0; j <= r - pos; j++) {
      dp[id][i + j] =
          max(dp[id][i + j], dp[id1][i] + dp[id2][j] + (j * i * com[pos]));
    }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> s[i];
  sort(s + 1, s + 1 + n);
  for (int i = 2; i <= n; i++) {
    int t = 0;
    for (int j = 0; j < min(s[i].size(), s[i - 1].size()); j++, t++) {
      if (s[i - 1][j] != s[i][j]) break;
    }
    com[i - 1] = t;
  }
  go(1, n);
  solve(1, n);
  cout << dp[1][k] << endl;
  return 0;
}
