#include <bits/stdc++.h>
using namespace std;
const int MAXN = 22;
int n, k, tmp;
string a[MAXN];
int f[MAXN][MAXN];
int pro(int x, int y) {
  int p = 0;
  if (a[x] == a[y]) return a[x].size();
  while (a[x][p] == a[y][p]) p++;
  return p;
}
int cou(int x) {
  int c = 0;
  for (int i = 0; i < n; i++)
    if (x & (1 << i)) c++;
  return c;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < i; j++) f[j][i] = f[i][j] = pro(i, j);
  tmp = (1 << n);
  vector<int> B;
  int ans = 0;
  for (int i = 0; i < tmp; i++) {
    if (cou(i) != k) continue;
    int ansi = 0;
    B.clear();
    for (int j = 0; j < n; j++)
      if (i & (1 << j)) B.push_back(j);
    for (int j = 0; j < B.size(); j++)
      for (int k = 0; k < j; k++) ansi += f[B[j]][B[k]];
    ans = max(ans, ansi);
  }
  cout << ans << endl;
  return 0;
}
