#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, K;
struct Trie {
  char c;
  int v;
  Trie* adj[26];
  Trie(char c) : c(c), v(0) {
    for (int i = (0); i < (26); i++) adj[i] = nullptr;
  }
  vector<int>* solve() {
    vector<vector<int>*> childVals;
    int leafCnt = v;
    for (int i = (0); i < (26); i++) {
      if (!adj[i]) continue;
      vector<int>* ret = adj[i]->solve();
      for (int i = (0); i < (ret->size()); i++) ret->at(i) += i * (i - 1) / 2;
      leafCnt += ret->size() - 1;
      childVals.push_back(ret);
    }
    vector<int>* knapsack = new vector<int>(leafCnt + 1);
    int currF = v;
    for (auto& child : childVals) {
      for (int i = currF; i >= 0; i--) {
        for (int k = (1); k < (child->size()); k++) {
          knapsack->at(i + k) =
              max(knapsack->at(i) + child->at(k), knapsack->at(i + k));
        }
      }
      currF += child->size() - 1;
    }
    return knapsack;
  }
  void add(string& str, int i = 0) {
    if (i == ((int)str.size())) {
      v++;
      return;
    }
    int c = str[i] - 'a';
    if (!adj[c]) adj[c] = new Trie(str[i]);
    adj[c]->add(str, i + 1);
  }
  void print(int i = 0) {
    for (int j = (0); j < (i); j++)
      if (true) cerr << ' ';
    if (true) cerr << c;
    vector<int>* ans = solve();
    for (int x : *ans)
      if (true) cerr << ' ' << x;
    if (true) cerr << endl;
    for (int j = (0); j < (26); j++)
      if (adj[j]) adj[j]->print(i + 1);
  }
};
Trie* trie = new Trie('R');
void solve() {
  cin >> N >> K;
  for (int i = (0); i < (N); i++) {
    string str;
    cin >> str;
    trie->add(str);
  }
  vector<int>* ans = trie->solve();
  cout << ans->at(K) << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
