#include <bits/stdc++.h>
using namespace std;
struct Node {
  Node* next[26];
  int end;
  Node() {
    for (int i = 0; i < (26); ++i) next[i] = 0;
    end = 0;
  }
};
void insert(Node* root, char* S, int N) {
  for (int i = 0; i < (N); ++i) {
    if (!root->next[S[i]]) root->next[S[i]] = new Node();
    root = root->next[S[i]];
  }
  root->end++;
}
int K;
int INF = 2000000000;
int* DP(Node* n) {
  int* result = new int[K + 1];
  result[0] = 0;
  for (int i = (1); i < (K + 1); ++i) result[i] = -1;
  for (int i = 0; i < (26); ++i)
    if (n->next[i]) {
      int* child = DP(n->next[i]);
      for (int j = (K + 1) - 1; j >= (0); --j)
        for (int k = 0; k < (j + 1); ++k)
          if (child[k] >= 0 && result[j - k] >= 0)
            result[j] =
                max(result[j], k * (k - 1) / 2 + result[j - k] + child[k]);
      delete[] child;
    }
  for (int j = (K + 1) - 1; j >= (0); --j)
    for (int k = 0; k < (min(n->end + 1, j + 1)); ++k)
      result[j] = max(result[j], result[j - k]);
  return result;
}
char buf[1000];
int main() {
  int N;
  scanf("%d%d", &N, &K);
  Node* root = new Node();
  for (int i = 0; i < (N); ++i) {
    scanf("%s", buf);
    int L = strlen(buf);
    for (int j = 0; j < (L); ++j) buf[j] -= 'a';
    insert(root, buf, L);
  }
  int* result = DP(root);
  printf("%d\n", (int)result[K]);
}
