#include <bits/stdc++.h>
using namespace std;
string s[40];
int precalc[40][40];
int calc(const string &a, const string &b) {
  int l = min(a.size(), b.size());
  for (int i = 0; i < (l); ++i)
    if (a[i] != b[i]) return i;
  return l;
}
int main(void) {
  ios::sync_with_stdio(false);
  int n, k, ans = 0;
  cin >> n >> k;
  for (int i = 0; i < (n); ++i) cin >> s[i];
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (n); ++j)
      if (i < j) precalc[i][j] = calc(s[i], s[j]);
  for (int mask = 0; mask < (1 << n); ++mask) {
    bitset<20> b(mask);
    if (b.count() == k) {
      int res = 0;
      for (int i = 0; i < (n); ++i)
        if (b[i])
          for (int j = 0; j < (n); ++j)
            if (i < j && b[j]) {
              res += precalc[i][j];
            }
      ans = max(ans, res);
    }
  }
  cout << ans << endl;
}
