#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[2000][501];
struct Trie {
  struct Node {
    int c;
    int next[26];
    Node() : c(0) { memset(next, -1, sizeof(next)); }
  } P[1000000];
  int sz;
  vector<int> dp[1000000];
  void init() {
    sz = 0;
    P[sz++] = Node();
  }
  void insert(char* s) {
    int p = 0;
    for (char* i = s; *i != '\0'; ++i) {
      int c = *i - 'a';
      if (P[p].next[c] == -1) {
        P[p].next[c] = sz;
        P[sz++] = Node();
      }
      p = P[p].next[c];
    }
    ++P[p].c;
  }
  void dfs(int u);
  void travel(int u) {
    printf("u = %d\n", u);
    for (int i = 0; i < 26; ++i) {
      if (P[u].next[i] != -1) {
        printf(" %c -> %d\n", i + 'a', P[u].next[i]);
      }
    }
    for (int i = 0; i < 26; ++i) {
      if (P[u].next[i] != -1) {
        travel(P[u].next[i]);
      }
    }
  }
  void gao() {
    dfs(0);
    printf("%d\n", dp[0][m]);
  }
} trie;
inline bool cmp(int lhs, int rhs) { return trie.P[lhs].c < trie.P[rhs].c; }
void Trie::dfs(int u) {
  int& total = P[u].c;
  vector<int> children;
  for (int i = 0; i < 26; ++i) {
    if (P[u].next[i] != -1) {
      children.push_back(P[u].next[i]);
      dfs(P[u].next[i]);
      total += P[P[u].next[i]].c;
    }
  }
  total = min(total, m);
  dp[u] = vector<int>(total + 1, 0);
  if (!children.empty()) {
    sort(children.begin(), children.end(), cmp);
    for (vector<int>::const_iterator i = children.begin(); i != children.end();
         ++i) {
      int t = *i;
      for (int j = total; j >= 0; --j) {
        for (int k = min(total - j, (int)dp[t].size() - 1); k >= 0; --k) {
          dp[u][j + k] = max(dp[u][j + k], dp[u][j] + dp[t][k]);
        }
      }
    }
  }
  if (u != 0) {
    for (int i = 0; i <= total; ++i) {
      dp[u][i] += i * (i - 1) / 2;
    }
  }
}
int main() {
  trie.init();
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
    trie.insert(s[i]);
  }
  trie.gao();
  return 0;
}
