#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
const int MAXLEN = 500;
const int INF = 0x3f3f3f3f;
template <class T>
void Read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = 0;
  while (c < '0' || '9' < c) {
    if (c == '-') flag = 1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (flag) x = -x;
}
int n, m;
char str[MAXN + 10][MAXLEN + 10];
int len[MAXN + 10];
int pos[MAXN + 10], height[MAXN + 10];
bool cmpstr(const int &a, const int &b) {
  return strcmp(str[a] + 1, str[b] + 1) < 0;
}
int mnp[MAXN * 4];
void build(int x, int l, int r) {
  if (l == r)
    mnp[x] = l;
  else {
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    mnp[x] = (height[mnp[x << 1]] <= height[mnp[x << 1 | 1]] ? mnp[x << 1]
                                                             : mnp[x << 1 | 1]);
  }
}
int findmn(int x, int l, int r, int ll, int rr) {
  if (l <= ll && rr <= r)
    return mnp[x];
  else {
    int mid = (ll + rr) >> 1;
    int ret = 0, t;
    if (l <= mid)
      t = findmn(x << 1, l, r, ll, mid),
      ret = (height[ret] > height[t] ? t : ret);
    if (mid < r)
      t = findmn(x << 1 | 1, l, r, mid + 1, rr),
      ret = (height[ret] > height[t] ? t : ret);
    return ret;
  }
}
void solve(int l, int r, int *dp) {
  memset(dp, 0, sizeof(int) * (r - l + 2));
  if (l == r) return;
  int mid = findmn(1, l, r - 1, 1, n - 1);
  int dpl[mid - l + 2], dpr[r - mid + 1];
  solve(l, mid, dpl);
  solve(mid + 1, r, dpr);
  int lenl = mid - l + 1, lenr = r - mid;
  for (int i = 0; i <= lenl; ++i)
    for (int j = 0; j <= lenr; ++j)
      dp[i + j] = max(dp[i + j], dpl[i] + dpr[j] + i * j * height[mid]);
}
int main() {
  Read(n), Read(m);
  if (n == 1 || !m)
    puts("0");
  else {
    for (int i = 1; i <= n; ++i)
      scanf("%s", str[i] + 1), pos[i] = i, len[i] = strlen(str[i] + 1);
    sort(pos + 1, pos + n + 1, cmpstr);
    for (int i = 1; i < n; ++i) {
      height[i] = 0;
      while (height[i] < min(len[pos[i]], len[pos[i + 1]]) &&
             str[pos[i]][height[i] + 1] == str[pos[i + 1]][height[i] + 1])
        ++height[i];
    }
    height[0] = INF;
    build(1, 1, n - 1);
    int dp[n + 5];
    solve(1, n, dp);
    printf("%d\n", dp[m]);
  }
}
