#include <bits/stdc++.h>
using namespace std;
string S[2100];
int n, K, Lcp[2100], f[2100], p[2100], _[2100], A, B;
long long F[2100][2100], _F[2100];
int Find(int x) { return f[x] == x ? x : f[x] = Find(f[x]); }
bool cmp(int a, int b) { return Lcp[a] > Lcp[b]; }
int main() {
  int i, j, k;
  cin >> n >> K;
  for (i = 0; i < n; i++) cin >> S[i];
  sort(S, S + n);
  for (i = 0; i + 1 < n; _[i] = i++)
    for (; Lcp[i] < S[i].length() && Lcp[i] < S[i + 1].length() &&
           S[i][Lcp[i]] == S[i + 1][Lcp[i]];
         Lcp[i]++)
      ;
  for (i = 0; i < n; i++) p[f[i] = i] = 1;
  std::sort(_, _ + n - 1, cmp);
  for (i = 0; i + 1 < n; i++) {
    memset(_F, 0, sizeof _F);
    A = Find(_[i]);
    B = Find(_[i] + 1);
    for (j = 0; j <= p[A]; j++)
      for (k = 0; k <= p[B] && j + k <= K; k++)
        if (_F[j + k] < F[A][j] + F[B][k] + j * k * Lcp[_[i]])
          _F[j + k] = F[A][j] + F[B][k] + j * k * Lcp[_[i]];
    f[A] = B;
    p[B] += p[A];
    memcpy(F[B], _F, sizeof _F);
  }
  cout << F[Find(1)][K];
  return 0;
}
