#include <bits/stdc++.h>
using namespace std;
struct trie {
  int val = 0;
  int sz = 0;
  vector<int> dp;
  trie* child[26] = {};
} root;
int n, k;
string s;
void add(trie* ro, int id = 0) {
  ro->sz++;
  if (id == s.size()) {
    ro->val++;
    return;
  }
  if (ro->child[s[id] - 'a'] == NULL) ro->child[s[id] - 'a'] = new trie;
  add(ro->child[s[id] - 'a'], id + 1);
  return;
}
void dfs(trie* me) {
  (me->dp).resize(me->val + 1, 0);
  int have = me->val;
  for (int w = 0; w < 26; w++) {
    if (me->child[w] == NULL) continue;
    dfs(me->child[w]);
    trie* ch = me->child[w];
    vector<int> a = me->dp;
    vector<int> b = ch->dp;
    (me->dp).resize(have + (ch->sz) + 1, 0);
    for (int i = 0; i <= have; i++)
      for (int j = 0; j <= ch->sz; j++) {
        int pay = a[i] + b[j];
        pay += j * (j - 1) / 2;
        (me->dp)[i + j] = max((me->dp)[i + j], pay);
      }
    have += ch->sz;
    (ch->dp).clear();
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    add(&root);
  }
  dfs(&root);
  cout << root.dp[k] << endl;
  cin >> n;
  return 0;
}
