#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
const int inf = 1e9;
const int md = 1e9 + 7;
int n, k;
int f[25][25];
string a[25];
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 = 0; j < n; ++j) {
      int k = 0;
      for (k = 0; k < min(a[i].size(), a[j].size()); ++k)
        if (a[i][k] != a[j][k]) break;
      f[i][j] = k;
    }
  int best = -1;
  for (int mask = 0; mask < (1 << n); ++mask) {
    int col = 0;
    for (int i = 0; i < n; ++i)
      if ((1 << i) & mask) ++col;
    if (col != k) continue;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      if ((1 << i) & mask)
        for (int j = i + 1; j < n; ++j)
          if ((1 << j) & mask) ans += f[i][j];
    }
    best = max(best, ans);
  }
  cout << best << endl;
  return 0;
}
