#include <bits/stdc++.h>
using namespace std;
const int N = 2002;
char s[N][503];
int a[N][N];
int cal(int x, int y) {
  int i = 0;
  while (s[x][i] && s[y][i]) {
    if (s[x][i] == s[y][i])
      ++i;
    else
      return i;
  }
  return i;
}
int get1(int x) { return x ? get1(x & (x - 1)) + 1 : 0; }
int r[1 << 20], t[22], ss, tt;
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int sum = 0;
  for (int i = 0; i < n; ++i) cin >> s[i];
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j) a[i][j] = a[j][i] = cal(i, j);
  for (int i = 0; i < (1 << n); ++i)
    if (get1(i) == k) r[ss++] = i;
  for (int i = 0; i < ss; ++i) {
    tt = 0;
    int sums = 0;
    for (int kk = 0; kk < n; ++kk)
      if (r[i] & (1 << kk)) t[tt++] = kk;
    for (int j = 0; j < k; ++j)
      for (int kk = j + 1; kk < k; ++kk) sums += a[t[j]][t[kk]];
    sum = max(sums, sum);
  }
  cout << sum << endl;
  return 0;
}
