#include <bits/stdc++.h>
using namespace std;
FILE* in;
FILE* out;
int n, k;
char a[1024][1024];
int ma3x[1024][1024];
int eval(char* a, char* b) {
  int len = min((int)strlen(a), (int)strlen(b));
  for (int i = 0; i < len; i++)
    if (a[i] != b[i]) return i;
  return len;
}
int popcnt(int n) {
  int ret = 0;
  while (n) {
    ret++;
    n &= (n - 1);
  }
  return ret;
}
int main(void) {
  in = stdin;
  out = stdout;
  fscanf(in, "%d %d", &n, &k);
  for (int i = 0; i < n; i++) fscanf(in, "%s", a[i]);
  for (int i = 0; i < n; i++)
    for (int c = i + 1; c < n; c++) ma3x[i][c] = eval(a[i], a[c]);
  int ans = 0;
  for (int mask = 0; mask < (1 << n); mask++) {
    if (popcnt(mask) == k) {
      int cur = 0;
      for (int i = 0; i < n; i++)
        if (mask & (1 << i))
          for (int c = i + 1; c < n; c++)
            if (mask & (1 << c)) cur += ma3x[i][c];
      ans = max(ans, cur);
    }
  }
  fprintf(out, "%d\n", ans);
  return 0;
}
