#include <bits/stdc++.h>
using namespace std;
int n, k;
int cost[100][100];
string s[100];
vector<int> mas;
int f(string s1, string s2) {
  int n = min(s1.length(), s2.length());
  for (int i = 0; i < n; i++) {
    if (s1[i] != s2[i]) return i;
  }
  return n;
}
int main(void) {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      cost[i][j] = cost[j][i] = f(s[i], s[j]);
    }
  }
  int ans = 0;
  for (int i = 0; i < (1 << n); i++) {
    mas.clear();
    for (int j = 0; j < 21; j++) {
      if ((i >> j) & 1) mas.push_back(j);
    }
    if (mas.size() != k) continue;
    int curans = 0;
    for (int j = 0; j < mas.size(); j++) {
      for (int k = j + 1; k < mas.size(); k++) {
        curans += cost[mas[j]][mas[k]];
      }
    }
    if (curans > ans) ans = curans;
  }
  cout << ans;
}
