#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') positive = 0;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
int N, K, tot, height[2005], f[4005][2005];
string a[2005];
inline int work(int l, int r) {
  if (l == r) return ++tot;
  int p = ++tot, m = l;
  for (int i = l; i < r; ++i) m = (height[i] < height[m] ? i : m);
  int left = work(l, m), right = work(m + 1, r);
  for (int i = 0; i <= K && i <= m - l + 1; ++i)
    for (int j = 0; i + j <= K && j <= r - m; ++j)
      f[p][i + j] =
          max(f[p][i + j], f[left][i] + f[right][j] + height[m] * i * j);
  return p;
}
int main() {
  N = read(), K = read();
  for (int i = 1; i <= N; ++i) cin >> a[i];
  sort(a + 1, a + N + 1);
  for (int i = 1, j; i < N; ++i) {
    for (j = 0; j < min(a[i].size(), a[i + 1].size()) && a[i][j] == a[i + 1][j];
         ++j)
      ;
    height[i] = j;
  }
  work(1, N);
  cout << f[1][K] << endl;
  return 0;
}
