#include <bits/stdc++.h>
using namespace std;
char str[22][505];
int pre[22][22];
int cal(int a, int b) {
  int la = strlen(str[a]);
  int lb = strlen(str[b]);
  int res = 0;
  for (; res < min(la, lb); res++) {
    if (str[a][res] != str[b][res]) return res;
  }
  return res;
}
int cmp(const void *a, const void *b) {
  char *x = (char *)a;
  char *y = (char *)b;
  return strcmp(x, y);
}
int main() {
  int n, k;
  while (~scanf("%d%d", &n, &k)) {
    for (int i = 0; i < n; i++) scanf(" %s", str[i]);
    qsort(str, n, sizeof(str[0]), cmp);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i != j) pre[i][j] = cal(i, j);
      }
    }
    int mx = (1 << n);
    int res = 0;
    for (int i = 0; i < mx; i++) {
      if (__builtin_popcount(i) == k) {
        int t = 0;
        for (int _i = 0; _i < n; _i++) {
          if (i & (1 << _i)) {
            for (int _j = _i + 1; _j < n; _j++) {
              if (i & (1 << _j)) {
                t += pre[_i][_j];
              }
            }
          }
        }
        res = max(res, t);
      }
    }
    printf("%d\n", res);
  }
  return 0;
}
