#include <bits/stdc++.h>
const int inf = 0x7fffffff;
const int N = 2000, K = 2001;
std::string s[N];
int n, k, lcp[N];
int f[N << 1][K], cnt;
void dp(const int &l, const int &r, const int &id) {
  if (l == r) return;
  int mid = 0;
  for (register int i = l + 1; i <= r; i++) {
    if (lcp[i] < lcp[mid]) mid = i;
  }
  const int lid = cnt++, rid = cnt++;
  dp(l, mid - 1, lid);
  dp(mid, r, rid);
  for (register int i = 0; i <= k; i++) {
    if (i > mid - l) break;
    for (register int j = 0; j <= k; j++) {
      if (j > r - mid + 1) break;
      if (i + j <= k)
        f[id][i + j] =
            std::max(f[id][i + j], f[lid][i] + f[rid][j] + lcp[mid] * i * j);
    }
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cin >> n >> k;
  for (register int i = 0; i < n; i++) {
    std::cin >> s[i];
  }
  std::sort(&s[0], &s[n]);
  lcp[0] = inf;
  for (register int i = 1; i < n; i++) {
    lcp[i] = std::min(s[i].length(), s[i - 1].length());
    for (register int j = 0; j < lcp[i]; j++) {
      if (s[i][j] != s[i - 1][j]) {
        lcp[i] = j;
      }
    }
  }
  dp(0, n - 1, cnt++);
  std::cout << f[0][k] << std::endl;
  return 0;
}
