#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
const int mod = (int)1e9 + 7;
const int logN = 18;
const int inf = 1e9;
const int N = 2e3 + 5;
int n, m, x, y, lcp[N];
string str[N];
vector<int> solve(int x, int y) {
  if (x >= y) {
    vector<int> v;
    v.resize(2, 0);
    return v;
  }
  int mid = min_element(lcp + x, lcp + y) - lcp, n = y - x + 1;
  vector<int> l = solve(x, mid), r = solve(mid + 1, y), cur;
  int ls = mid - x + 1, rs = y - mid;
  cur.resize(min(ls + rs + 1, m + 1), 0);
  for (int m = 1; m <= min(::m, y - x + 1); m++) {
    for (int i = max(m - rs, 0); i <= m && i <= ls; i++) {
      cur[m] = max(cur[m], l[i] + r[m - i] + i * (m - i) * lcp[mid]);
    }
  }
  return cur;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) cin >> str[i];
  sort(str + 1, str + n + 1);
  for (int i = 1; i <= n - 1; i++) {
    int lcp = 0;
    while (lcp < min(str[i].size(), str[i + 1].size()) &&
           str[i][lcp] == str[i + 1][lcp])
      lcp++;
    ::lcp[i] = lcp;
  }
  cout << solve(1, n).back() << '\n';
  return 0;
}
