#include <bits/stdc++.h>
using namespace std;
string Get() {
  char c;
  while (c = getchar(), c < 'a' || c > 'z')
    ;
  string S = "";
  while (c >= 'a' && c <= 'z') {
    S += c;
    c = getchar();
  }
  return S;
}
const int Seed = 19961021;
const int inf = 1000000000;
int K, Counter;
string S[2000];
int Len[2000], X[2000];
long long Hash[2000][501];
int DP[2000][2001];
int LCP(int X, int Y) {
  int Left = 0, Right = min(Len[X], Len[Y]);
  while (Left < Right) {
    int Mid = (Left + Right + 1) / 2;
    if (Hash[X][Mid] == Hash[Y][Mid])
      Left = Mid;
    else
      Right = Mid - 1;
  }
  return Left;
}
int Cmp(int X, int Y) {
  int L = LCP(X, Y);
  if (L == Len[Y]) return false;
  if (L == Len[X]) return true;
  return S[X][L] < S[Y][L];
}
int Solve(int L, int R) {
  if (L == R) return 0;
  int T = Counter++, Mid = L;
  for (int i = L + 1; i < R; i++)
    if (X[i] < X[Mid]) Mid = i;
  int T0 = Solve(L, Mid), T1 = Solve(Mid + 1, R);
  for (int i = 0; i <= K; i++) {
    DP[T][i] = -inf;
    if (i > R - L + 1) continue;
    for (int j = 0, k = i; k >= 0; j++, k--)
      if (DP[T0][j] >= 0 && DP[T1][k] >= 0)
        DP[T][i] = max(DP[T][i], DP[T0][j] + DP[T1][k] + j * k * X[Mid]);
  }
  return T;
}
int main() {
  int N;
  scanf("%d%d", &N, &K);
  if (K == 1) {
    printf("0\n");
    return 0;
  }
  for (int i = 0; i < N; i++) {
    S[i] = Get();
    Len[i] = S[i].size();
    for (int j = Hash[i][0] = 0; j < Len[i]; j++)
      Hash[i][j + 1] = Hash[i][j] * Seed + S[i][j];
  }
  static int A[2000];
  for (int i = 0; i < N; i++) A[i] = i;
  sort(A, A + N, Cmp);
  N--;
  for (int i = 0; i < N; i++) X[i] = LCP(A[i], A[i + 1]);
  DP[0][0] = DP[0][1] = 0;
  for (int i = 2; i <= K; i++) DP[0][i] = -inf;
  Counter = 1;
  Solve(0, N);
  printf("%d\n", DP[1][K]);
  return 0;
}
