#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void umax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void umin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
const int inf = 1e9 + 143;
const long long longinf = 1e18 + 143;
inline int read() {
  int x;
  scanf(" %d", &x);
  return x;
}
const int N = 2050;
int n, k;
char foo[555];
string s[N];
int a[N];
vector<int> solve(int l, int r) {
  if (l >= r) {
    return vector<int>(k + 1, 0);
  }
  int cut = -1, mn = inf;
  for (int i = l; i < r; i++) {
    if (mn > a[i]) {
      mn = a[i];
      cut = i;
    }
  }
  int lsz = min(k, cut - l + 1);
  int rsz = min(k, r - cut);
  vector<int> fl = solve(l, cut);
  vector<int> fr = solve(cut + 1, r);
  vector<int> f(k + 1, 0);
  for (int x = 0; x <= r - l + 1 && x <= k; x++) {
    if (lsz < rsz) {
      for (int y = 0; y <= x && y <= lsz; y++) {
        if (x - y <= rsz) umax(f[x], fl[y] + fr[x - y] + y * (x - y) * mn);
      }
    } else {
      for (int y = 0; y <= x && y <= rsz; y++) {
        if (x - y <= lsz) umax(f[x], fr[y] + fl[x - y] + y * (x - y) * mn);
      }
    }
  }
  return f;
}
int main() {
  n = read();
  k = read();
  for (int i = 0; i < n; i++) {
    scanf(" %s", foo);
    s[i] = foo;
  }
  sort(s, s + n);
  for (int i = 0; i < n - 1; i++) {
    int lcp = 0;
    while (lcp < s[i].size() && lcp < s[i + 1].size() &&
           s[i][lcp] == s[i + 1][lcp])
      ++lcp;
    a[i] = lcp;
  }
  vector<int> f = solve(0, n - 1);
  printf("%d\n", f[k]);
  return 0;
}
