#include <bits/stdc++.h>
using namespace std;
const int maxn = 2100;
int n, K;
string A[maxn];
namespace Ninit {
char s[1100];
void init() {
  int i;
  scanf("%d%d", &n, &K);
  for (i = 0; i < n; ++i) {
    scanf("%s", s), A[i] = string(s);
  }
  sort(A, A + n);
}
}  // namespace Ninit
namespace Nsolve {
long long F[2 * maxn][maxn], G[maxn];
int dfs(int x, int y, int v) {
  static int tot = 0;
  int i, j, l, r, t, p = tot++;
  if (x + 1 == y) return p;
  for (t = i = x + 1; i < y; ++i)
    if (G[i] < G[t]) t = i;
  l = dfs(x, t, G[t]), r = dfs(t, y, G[t]);
  for (i = 0; i <= t - x; ++i)
    for (j = 0; j <= y - t; ++j)
      F[p][i + j] =
          max(F[p][i + j],
              F[l][i] + F[r][j] + (G[t] - v) * (i + j) * (i + j - 1) / 2);
  return p;
}
void solve() {
  int i, x;
  for (i = 1; i < n; ++i) {
    for (x = 0;
         x < A[i - 1].size() && x < A[i].size() && A[i - 1][x] == A[i][x]; ++x)
      ;
    G[i] = x;
  }
  dfs(0, n, 0);
  cout << F[0][K] << endl;
}
}  // namespace Nsolve
int main() {
  Ninit::init();
  Nsolve::solve();
  return 0;
}
