#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long BIG = 1446803456761533460LL;
const int Big = 336860180;
const long long int INF = LONG_LONG_MAX;
const long long int adj4[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const long long int adj8[8][2] = {{0, 1},   {0, -1}, {1, 0},  {-1, 0},
                                  {-1, -1}, {1, -1}, {-1, 1}, {1, 1}};
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long int powMod(long long int a, long long int b) {
  long long int n = 1;
  long long int p = a;
  while (b > 0) {
    if (b % 2 == 1) {
      n *= p;
      n %= MOD;
    }
    p *= p;
    p %= MOD;
    b /= 2;
  }
  return n;
}
long long int modularInverse(long long int a) { return powMod(a, MOD - 2); }
stringstream sss;
const long long int maxn = 2010;
long long int n, k;
string S[maxn];
long long int lcp[maxn];
vector<long long int> solve(long long int l, long long int r) {
  vector<long long int> dp(k + 1, -BIG);
  dp[0] = dp[1] = 0;
  if (r - l <= 1) {
    return dp;
  }
  long long int mni = l;
  for (long long int i = (l); i < (r - 1); ++i) {
    if (lcp[i] < lcp[mni]) {
      mni = i;
    }
  }
  vector<long long int> lt = solve(l, mni + 1);
  vector<long long int> rt = solve(mni + 1, r);
  for (long long int i = (0); i < (k + 1); ++i) {
    for (long long int j = (0); j < (i + 1); ++j) {
      dp[i] = max(dp[i], (lt[j] + rt[i - j] + lcp[mni] * j * (i - j)));
    }
  }
  return dp;
}
void MAIN() {
  cin >> n >> k;
  for (long long int i = (0); i < (n); ++i) {
    cin >> S[i];
  }
  sort(S, S + n);
  for (long long int i = (0); i < (n - 1); ++i) {
    long long int j = 0;
    long long int len = min(S[i].size(), S[i + 1].size());
    while (j < len && S[i][j] == S[i + 1][j]) {
      ++j;
    }
    lcp[i] = j;
  }
  cout << (solve(0, n)[k]) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  sss << R"(
4 4
aaa
abba
abbc
abbd
    )";
  MAIN();
  return 0;
}
