#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
string a[25];
int n, k, mx, cost[25][25], b[25];
void gen(int ind, int take) {
  if (take == k) {
    int sum = 0;
    for (int i = 0; i < k; i++)
      for (int j = i + 1; j < k; j++) sum += cost[b[i]][b[j]];
    mx = max(mx, sum);
    return;
  }
  if (n - ind >= k - take) {
    b[take] = ind;
    gen(ind + 1, take + 1);
    gen(ind + 1, take);
  }
}
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 = i + 1; j < n; j++) {
      int len = 0, v = min(a[i].size(), a[j].size());
      while (len < v && a[i][len] == a[j][len]) len++;
      cost[i][j] = cost[j][i] = len;
    }
  gen(0, 0);
  cout << mx;
  return 0;
}
