#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void JIZZ(string output = "") {
  cout << output;
  exit(0);
}
const long double PI = 3.14159265358979323846264338327950288;
const long double eps = 1e-13;
const long long mod = 1e9 + 7;
string s[2005];
map<int, int> rec[505][2005];
pair<int, int> st[13][2005];
pair<int, int> Q(int l, int r) {
  ;
  ;
  if (l == r) {
    ;
    ;
    return st[0][l];
  }
  int dd = r - l + 1;
  ;
  ;
  int z = 0;
  while (dd) dd >>= 1, ++z;
  --z;
  ;
  ;
  ;
  ;
  return min(st[z][l], st[z][r - (1 << z) + 1]);
}
int go(int i, int l, int r) {
  if (l > r) return 0;
  if (l == r && i) return 0;
  ;
  ;
  if (i == 0) return 0;
  if (i > r - l + 1) return 0;
  if (r == l + 1 && i >= 2) return Q(l + 1, r).first;
  if (r == l + 1) return 0;
  auto it = rec[i][l].find(r);
  if (it != rec[i][l].end()) return it->second;
  auto p = Q(l + 1, r);
  int mx = 0;
  ;
  ;
  for (int lz = 0; lz <= i; ++lz) {
    mx = max(mx, lz * (i - lz) * p.first + go(lz, l, p.second - 1) +
                     go(i - lz, p.second, r));
    ;
    ;
  };
  ;
  return rec[i][l][r] = mx;
}
int meow(string a, string b) {
  int z = min(a.size(), b.size());
  for (int i = 0; i < z; ++i)
    if (a[i] != b[i]) return i;
  return z;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> s[i];
  sort(s, s + n);
  for (int i = 1; i < n; ++i)
    st[0][i] = pair<int, int>(meow(s[i - 1], s[i]), i);
  for (int z = 1; z < 12; ++z) {
    for (int j = 1; j < n; ++j) {
      st[z][j] = min(st[z - 1][j], st[z - 1][j + (1 << (z - 1))]);
    }
  }
  for (int i = 1; i < n; ++i)
    ;
  ;
  ;
  ;
  cout << go(k, 0, n - 1) << endl;
}
