#include <bits/stdc++.h>
using namespace std;
const int N = 50002, M = 26, nil = 0, L = 512, NN = 102;
struct Anode {
  int ch[M], fail, num;
} T[N];
int root, n, m, d[N], f[N][NN], g[N][NN], num;
char s[L];
inline void newnode(int& x) {
  x = ++num;
  T[x].fail = nil;
  for (int i = 0; i < M; ++i) T[x].ch[i] = nil;
}
inline void clear() {
  newnode(root);
  for (int i = 0; i < M; ++i) T[nil].ch[i] = root;
}
inline void insert(char* s) {
  int k = root, t;
  for (int i = 0; s[i]; ++i) {
    t = s[i] - 'a';
    if (T[k].ch[t] == nil) newnode(T[k].ch[t]);
    k = T[k].ch[t];
  }
  ++T[k].num;
}
inline void dfs(int x) {
  for (int i = 0; i < M; ++i)
    if (T[x].ch[i] != nil) {
      dfs(T[x].ch[i]);
      T[x].num += T[T[x].ch[i]].num;
    }
}
inline void work(int x, int k) {
  for (int i = 0; i < M; ++i)
    if (T[x].ch[i] != nil) work(T[x].ch[i], min(k, T[T[x].ch[i]].num));
  for (int i = 0; i < M; ++i)
    if (T[x].ch[i] != nil) {
      for (int j = k; j; --j) g[x][j] = f[x][j];
      for (int l = 1; l <= min(k, T[T[x].ch[i]].num); ++l) {
        for (int j = k; j >= l; --j)
          f[x][j] = max(f[x][j], g[x][j - l] + f[T[x].ch[i]][l]);
      }
    }
  if (x != root)
    for (int i = 1; i <= k; ++i) f[x][i] += (i - 1) * i / 2;
}
int main() {
  scanf("%d%d", &n, &m);
  clear();
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s);
    insert(s);
  }
  dfs(root);
  work(root, m);
  printf("%d\n", f[root][m]);
}
