#include <bits/stdc++.h>
using namespace std;
struct TrieNode {
  int term;
  int ch[26];
  int cntdown;
  int values[102];
  TrieNode() {
    memset(values, 0xff, sizeof(values));
    memset(ch, 0xff, sizeof(ch));
    term = 0;
  }
};
int C2(int x) { return x * (x - 1) / 2; }
class Trie {
 public:
  Trie() { nodes.push_back(TrieNode()); }
  int addWord(char* s) { return addWord(s, 0); }
  void calcCnt() { calcCnt(0); }
  int getValue(int id, int k) {
    if (k == 0) return 0;
    TrieNode& cur = nodes[id];
    if (k > cur.cntdown) k = cur.cntdown;
    if (cur.values[k] != -1) return cur.values[k];
    vector<int> f(k + 1, 0);
    for (int i = 0; i < (int)(26); i++)
      if (cur.ch[i] != -1) {
        for (int j = k; j >= 1; j--)
          for (int kp = 0; kp < (int)(j + 1); kp++) {
            f[j] = max(f[j], f[kp] + C2(min(j - kp, nodes[cur.ch[i]].cntdown)) +
                                 getValue(cur.ch[i], j - kp));
          }
      }
    return cur.values[k] = f[k];
  }

 private:
  vector<TrieNode> nodes;
  int addWord(char* s, int id) {
    for (; *s != 0; s++) {
      int nxt = (*s) - 'a';
      if (nodes[id].ch[nxt] == -1) {
        nodes[id].ch[nxt] = nodes.size();
        nodes.push_back(TrieNode());
      }
      id = nodes[id].ch[nxt];
    }
    nodes[id].term++;
    return id;
  }
  int calcCnt(int id) {
    TrieNode& cur = nodes[id];
    cur.cntdown = cur.term;
    for (int i = 0; i < (int)(26); i++)
      if (cur.ch[i] != -1) cur.cntdown += calcCnt(cur.ch[i]);
    return cur.cntdown;
  }
};
Trie trie;
int n, k;
char s[510];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < (int)(n); i++) {
    scanf("%s", s);
    trie.addWord(s);
  }
  trie.calcCnt();
  printf("%d\n", trie.getValue(0, k));
  return 0;
}
