#include <bits/stdc++.h>
using namespace std;
int n, k;
string s[2008];
char tmp[2008];
int h[2008];
struct Tprogram {
  void open() {
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
  }
  void close() {}
  int lcp(string s1, string s2) {
    int n = s1.size(), m = s2.size();
    for (int i = 0; i <= (n < m ? n : m) - 1; i++)
      if (s1[i] != s2[i]) return i;
    return (n < m ? n : m);
  }
  void init() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) {
      scanf("%s", &tmp);
      int m = strlen(tmp);
      for (int j = 0; j <= m - 1; j++) s[i].push_back(tmp[j]);
    }
    sort(s + 1, s + n + 1);
    for (int i = 1; i <= n - 1; i++) h[i] = lcp(s[i], s[i + 1]);
  }
  vector<int> Dp(int l, int r) {
    vector<int> a;
    a.clear();
    for (int i = 0; i <= r - l + 1; i++) a.push_back(0);
    if (l == r) return a;
    int pos = l;
    for (int i = l; i <= r - 1; i++)
      if (h[i] < h[pos]) pos = i;
    vector<int> b = Dp(l, pos), c = Dp(pos + 1, r);
    for (int i = 0; i <= b.size() - 1; i++)
      for (int j = 0; j <= c.size() - 1; j++)
        a[i + j] = (b[i] + c[j] + i * j * h[pos] > a[i + j]
                        ? b[i] + c[j] + i * j * h[pos]
                        : a[i + j]);
    return a;
  }
  void work() {
    vector<int> a = Dp(1, n);
    printf("%d\n", a[k]);
  }
} Program;
int main() {
  Program.init();
  Program.work();
  return 0;
}
