#include <bits/stdc++.h>
using namespace std;
vector<string> v;
int d[2000][2000] = {0};
int dp[1 << 20] = {0};
int dis(string &a, string &b) {
  int vi = a.length(), vj = b.length(), k = 0;
  while (k < vi && k < vj && a[k] == b[k]) k++;
  return k;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<string> v;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  sort(v.begin(), v.end());
  if (k == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      int vi = v[i].length(), vj = v[j].length(), k = 0;
      while (k < vi && k < vj && v[i][k] == v[j][k]) k++;
      d[i][j] = k;
    }
  int maxsum = 0;
  dp[0] = 0;
  if (k == 1) {
    cout << 0;
    return 0;
  }
  for (int mask = 1; mask < (1 << n); mask++) {
    int temp = 0;
    int size = 0;
    for (int j = 0; j < n; j++)
      if (mask & (1 << j)) size++;
    for (int j = 0; j < n; j++)
      if (mask & (1 << j)) {
        int submask = mask ^ (1 << j);
        int t = dp[submask];
        for (int i = 0; i < n; i++)
          if (submask & (1 << i)) {
            t += d[i][j];
          }
        temp = t;
        break;
      }
    dp[mask] = temp;
    if (size == k) maxsum = max(maxsum, temp);
  }
  cout << maxsum;
}
