#include <bits/stdc++.h>
using namespace std;
const int N = 2005, L = 600;
string S[N];
int n, k, lcp[N], f[N][N], cid;
int dp(int l, int r) {
  if (l >= r) return cid++;
  int mv = N, mp = -1;
  for (int i = l; i < r; ++i)
    if (lcp[i] < mv) mv = lcp[mp = i];
  int ld = dp(l, mp), rd = dp(mp + 1, r);
  for (int i = 0; l + i - 1 <= mp; ++i)
    for (int j = 0; mp + 1 + j - 1 <= r; ++j)
      f[cid][i + j] = max(f[cid][i + j], f[ld][i] + f[rd][j] + lcp[mp] * i * j);
  return cid++;
}
int main() {
  cin >> n >> k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) cin >> S[i];
  sort(S + 1, S + 1 + n);
  for (int i = 1; i <= n; ++i) S[i].push_back((i & 1) ? '#' : '$');
  for (int i = 1; i < n; ++i) {
    for (lcp[i] = 1; S[i][lcp[i] - 1] == S[i + 1][lcp[i] - 1]; ++lcp[i])
      ;
    --lcp[i];
  }
  cout << f[dp(1, n)][k] << endl;
  return 0;
}
