#include <bits/stdc++.h>
using namespace std;
const int MAX = 22;
const int INF = 1 << 30;
const double EPS = 1e-7;
int N, K;
int ans;
int r[MAX], len[MAX];
int f[MAX][MAX];
char p[MAX][505];
bool u[MAX];
int foo(int i, int j) {
  int k = 0;
  int l = min(len[i], len[j]);
  while (k < l && p[i][k] == p[j][k]) ++k;
  return k;
}
void calc(int p, int l) {
  if (p == K) {
    int cur = 0;
    for (int i = 0; i < (K - 1); ++i)
      for (int j = (i + 1); j < K; ++j) cur += f[r[i]][r[j]];
    ans = max(ans, cur);
    return;
  }
  for (int i = l; i < N; i++)
    if (!u[i]) {
      u[i] = 1;
      r[p] = i;
      calc(p + 1, i + 1);
      u[i] = 0;
    }
}
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i < (N); ++i) scanf("%s", p[i]), len[i] = strlen(p[i]);
  for (int i = 0; i < (N); ++i)
    for (int j = (i + 1); j < N; ++j) f[i][j] = f[j][i] = foo(i, j);
  calc(0, 0);
  cout << ans << endl;
  return 0;
}
