#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
int dp[maxn][maxn];
int n, m, same[maxn], tot;
string s[maxn];
int solve(int L, int R) {
  if (L == R) return n;
  int mid = maxn, pl = 0;
  for (int i = L; i <= R - 1; ++i)
    if (mid > same[i]) mid = same[i], pl = i;
  int p = solve(L, pl), q = solve(pl + 1, R);
  int tmp = ++tot;
  for (int i = 0; i <= pl - L + 1; ++i)
    for (int j = 0; j <= R - pl; ++j)
      dp[tmp][i + j] = max(dp[tmp][i + j], dp[p][i] + dp[q][j] + mid * i * j);
  return tmp;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) cin >> s[i];
  sort(s + 1, s + n + 1);
  memset(same, 0, sizeof(same));
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i < n; ++i)
    while (s[i][same[i]] == s[i + 1][same[i]] &&
           same[i] < min(s[i].length(), s[i + 1].length()))
      same[i]++;
  printf("%d\n", dp[solve(1, n)][m]);
}
