#include <bits/stdc++.h>
using namespace std;
char ss[1000];
int pref[100][100], p[100], n, k;
string second[100];
int main() {
  scanf("%d%d\n", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%s", &ss);
    second[i] = ss;
  }
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j) {
      int k = 0;
      while (k < second[i].size() && k < second[j].size() &&
             second[i][k] == second[j][k])
        ++k;
      pref[i][j] = pref[j][i] = k;
    }
  int ans = 0;
  for (int mask = 0; mask < (1 << n); ++mask)
    if (__builtin_popcount(mask) == k) {
      int m = 0;
      for (int i = 0; i < n; ++i)
        if (mask & (1 << i)) p[m++] = i;
      int cur = 0;
      for (int i = 0; i < k; ++i)
        for (int j = i + 1; j < k; ++j) cur += pref[p[i]][p[j]];
      ans = max(ans, cur);
    }
  cout << ans << endl;
  return 0;
}
