#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  int l = v.size();
  for (int i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
int getlcp(string& s, string& t) {
  int k = 0;
  for (int i = 0; i < s.length() and i < t.length(); i++) {
    if (s[i] != t[i]) break;
    k++;
  }
  return k;
}
vector<int> lcp;
vector<int> solve(int l, int r) {
  if (l == r) {
    return {0, 0};
  }
  int m = l;
  for (int i = l + 1; i + 1 <= r; i++) {
    if (lcp[i] < lcp[m]) m = i;
  }
  vector<int> left = solve(l, m);
  vector<int> right = solve(m + 1, r);
  vector<int> res(r - l + 2, 0);
  for (int i = 0; i < left.size(); i++) {
    for (int j = 0; j < right.size(); j++) {
      res[i + j] = max(res[i + j], left[i] + right[j] + i * j * lcp[m]);
    }
  }
  assert(res[0] == res[1] and res[1] == 0);
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<string> v(n);
  lcp.resize(n - 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  for (int i = 0; i + 1 < n; i++) {
    lcp[i] = getlcp(v[i], v[i + 1]);
  }
  cout << solve(0, n - 1)[k] << endl;
  return 0;
}
