#include <bits/stdc++.h>
using namespace std;
char second[1111];
int to[1111111][26];
int cnt[1111111];
int dp[555][2222];
int vn, root, n, k;
void add() {
  int n = strlen(second);
  int u = root;
  for (int i = 0; i < n; ++i) {
    int &v = to[u][second[i] - 'a'];
    if (v == -1) {
      v = vn++;
    }
    ++cnt[v];
    u = v;
  }
}
void calc(int u, int d) {
  for (int j = 0; j <= cnt[u]; ++j) dp[d][j] = -1;
  dp[d][0] = 0;
  int tt = cnt[u];
  for (int i = 0; i < 26; ++i)
    if (to[u][i] != -1) {
      int v = to[u][i];
      tt -= cnt[v];
      calc(v, d + 1);
      for (int j = cnt[u] - 1; j >= 0; --j)
        if (dp[d][j] != -1) {
          for (int k = 1; k <= cnt[v] && j + k <= cnt[u]; ++k)
            if (dp[d + 1][k] != -1) {
              dp[d][j + k] = max(dp[d][j + k], dp[d][j] + dp[d + 1][k]);
            }
        }
    }
  if (tt > 0) {
    for (int j = cnt[u] - tt; j >= 0; --j)
      if (dp[d][j] != -1) {
        for (int k = 1; k <= tt; ++k)
          dp[d][j + k] = max(dp[d][j + k], dp[d][j]);
      }
  }
  if (u != 0) {
    for (int k = 1; k <= cnt[u]; ++k)
      if (dp[d][k] != -1) {
        dp[d][k] += k * (k - 1) / 2;
      }
  }
}
int main() {
  memset(to, -1, sizeof(to));
  vn = 1;
  scanf("%d%d\n", &n, &k);
  for (int i = 0; i < n; ++i) {
    gets(second);
    add();
  }
  cnt[0] = n;
  calc(0, 0);
  cout << dp[0][k] << endl;
  return 0;
}
