#include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
string s[2005];
int n, K;
int lcp[2005];
int prof[2005][2005];
struct segtree {
  pair<int, int> val[10000];
  int n;
  void init(int n_) {
    n = 1;
    while (n < n_) n <<= 1;
    for (int i = 0; i < n * 2; ++i) val[i] = make_pair(INF, INF);
  }
  void set(int k, int a) {
    val[k + n - 1] = make_pair(a, k);
    k += n - 1;
    while (k > 0) {
      k = (k - 1) / 2;
      val[k] = min(val[k * 2 + 1], val[k * 2 + 2]);
    }
  }
  pair<int, int> query(int a, int b, int i, int l, int r) {
    if (a <= l && r <= b) return val[i];
    if (b <= l || r <= a) return make_pair(INF, INF);
    int md = (l + r) >> 1;
    return min(query(a, b, i * 2 + 1, l, md), query(a, b, i * 2 + 2, md, r));
  }
};
segtree seg;
int dp[105][105][105];
int rec(int s, int e, int k) {
  k = min(k, e - s);
  if (e - s == 1) return 0;
  if (dp[s][e][k] != -1) return dp[s][e][k];
  pair<int, int> mini = seg.query(s, e - 1, 0, 0, seg.n);
  for (int i = 0; i < k + 1; ++i)
    dp[s][e][k] = max(dp[s][e][k], rec(s, mini.second + 1, i) +
                                       rec(mini.second + 1, e, k - i) +
                                       i * (k - i) * mini.first);
  return dp[s][e][k];
}
int main() {
  scanf("%d%d", &n, &K);
  for (int i = 0; i < n; ++i) cin >> s[i];
  sort(s, s + n);
  seg.init(n);
  for (int i = 0; i < n - 1; ++i) {
    int& t = lcp[i];
    for (t = 0;
         t < s[i].size() && t < s[i + 1].size() && s[i][t] == s[i + 1][t]; ++t)
      ;
    seg.set(i, t);
  }
  for (int i = 0; i < n; ++i) prof[i][i] = 0;
  for (int len = 1; len <= n - 1; ++len)
    for (int i = 0; i < n - len; ++i) {
      int j = i + len;
      pair<int, int> mini = seg.query(i, j, 0, 0, seg.n);
      prof[i][j] = prof[i][mini.second] + prof[mini.second + 1][j] +
                   (mini.second - i + 1) * (j - mini.second) * mini.first;
    }
  memset(dp, -1, sizeof(dp));
  printf("%d\n", rec(0, n, K));
  return 0;
}
