#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
int a, b, c, d, i, j, n, m, k;
char str[21][502];
int ds[21][21];
int main() {
  scanf("%d%d", &n, &k);
  for (int _n((n)-1), i(0); i <= _n; i++) {
    scanf("%s", str[i]);
  }
  for (int _n((n)-1), i(0); i <= _n; i++) {
    for (int _n((i)-1), j(0); j <= _n; j++) {
      a = 0;
      while (str[i][a] == str[j][a] && str[i][a]) ++a;
      ds[i][j] = ds[j][i] = a;
    }
  }
  int ans = -1000000000;
  for (int _n((1 << n) - 1), mask(0); mask <= _n; mask++) {
    c = 0;
    for (int _n((n)-1), i(0); i <= _n; i++)
      if (mask & 1 << i) ++c;
    if (c != k) continue;
    int cur = 0;
    for (int _n((n)-1), i(0); i <= _n; i++) {
      if (~mask & 1 << i) continue;
      for (int _n((i)-1), j(0); j <= _n; j++) {
        if (mask & 1 << j) cur += ds[i][j];
      }
    }
    if (cur > ans) ans = cur;
  }
  printf("%d\n", ans);
}
