#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const long long INF_LL = 1000000000000000000LL;
const double pi = 2 * acos(0.0);
const int N = 2048;
complex<double> a[N], b[N];
complex<double> w[N], c[N], d[N];
void fft(complex<double> *a, complex<double> *b, int n, int add = 1) {
  if (n == 1) {
    *b = *a;
    return;
  }
  fft(a, b, n / 2, add * 2);
  fft(a + add, b + n / 2, n / 2, add * 2);
  for (int i(0), _b(n / 2); i < _b; ++i) b[i] += b[i + n / 2] * w[i * add];
  for (int i(n / 2), _b(n); i < _b; ++i)
    b[i] = b[i - n / 2] - b[i] * w[(i - n / 2) * add] + b[i] * w[i * add];
}
void mul(vector<int> &va, vector<int> &vb) {
  for (int i(0), _b(int((va).size())); i < _b; ++i) a[i] = va[i];
  for (int i(int((va).size())), _b(N); i < _b; ++i) a[i] = 0;
  for (int i(0), _b(int((vb).size())); i < _b; ++i) b[i] = vb[i];
  for (int i(int((vb).size())), _b(N); i < _b; ++i) b[i] = 0;
  fft(a, c, N);
  fft(b, d, N);
  for (int i(0), _b(N); i < _b; ++i) c[i] *= d[i];
  for (int i(0), _b(N); i < _b; ++i) w[i] = polar(1.0, -2 * pi * i / N);
  fft(c, d, N);
}
void smax(int &a, int b) {
  if (a < b) a = b;
}
const int h = 2002;
int n, k;
string s[h];
vector<int> f(int l, int r, int d) {
  if (l + 1 == r) return vector<int>(2, 0);
  vector<int> a(r - l + 1, 0);
  int kl = 0;
  while (l < r && int((s[l]).size()) == d) ++kl, ++l;
  bool first = true;
  for (int i(l + 1), _b(r + 1); i < _b; ++i)
    if (i == r || s[i - 1][d] != s[i][d]) {
      vector<int> t = f(l, i, d + 1);
      for (int j(2), _b(int((t).size())); j < _b; ++j) t[j] += j * (j - 1) / 2;
      if (first) {
        for (int j(0), _b(int((t).size())); j < _b; ++j) a[j] = t[j];
        for (int j(0), _b(kl); j < _b; ++j)
          a[int((t).size()) + j] = a[int((t).size()) - 1];
        first = false;
      } else {
        for (int u(int((a).size()) - 1), _b(0); u >= _b; --u)
          for (int j(1), _b(min(int((t).size()), int((a).size()) - u)); j < _b;
               ++j)
            smax(a[u + j], a[u] + t[j]);
      }
      l = i;
    }
  return a;
}
int main() {
  for (int i(0), _b(N); i < _b; ++i) w[i] = polar(1.0, 2 * pi * i / N);
  scanf("%d%d", &n, &k);
  char c[555];
  for (int i(0), _b(n); i < _b; ++i) {
    scanf("%s", c);
    s[i] = c;
  }
  sort(s, s + n);
  vector<int> ans = f(0, n, 0);
  printf("%d\n", ans[k]);
  return 0;
}
