#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long double EPS = 1e-9;
template <class second, class T>
ostream& operator<<(ostream& os, const pair<second, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const unordered_set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class second, class T>
ostream& operator<<(ostream& os, const unordered_map<second, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const multiset<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class second, class T>
ostream& operator<<(ostream& os, const map<second, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void dbs(string str, T t) {
  cerr << str << " : " << t << "\n";
}
template <class T, class... second>
void dbs(string str, T t, second... s) {
  long long idx = str.find(',');
  cerr << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class T>
void prc(T a, T b) {
  cerr << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cerr << ", ";
    cerr << *i;
  }
  cerr << "]\n";
}
long long binpow(long long b, long long p, long long mod) {
  long long ans = 1;
  for (; p; p >>= 1) {
    if (p & 1) ans = ans * b % mod;
    b = b * b % mod;
  }
  return ans;
}
void pre() {}
int n, k;
long long dp[101][101][101];
string s[101];
long long lcp[101];
long long len[101];
void solve() {
  cin >> n >> k;
  for (long long i = 0; i < n; ++i) cin >> s[i];
  sort(s, s + n);
  for (long long i = 0; i < n; ++i) {
    len[i] = s[i].length();
  }
  for (long long i = 0; i < n - 1; ++i) {
    lcp[i] = 0;
    while (lcp[i] < len[i] && lcp[i] < len[i + 1] &&
           s[i][lcp[i]] == s[i + 1][lcp[i]])
      lcp[i]++;
  }
  for (int r = 1; r <= n; r++) {
    for (int l = r - 2; l >= 0; l--) {
      int mid = min_element(lcp + l, lcp + r - 1) - (lcp + l) + l;
      for (int p = 2; p <= k; p++) {
        for (int c1 = 0; c1 <= p; c1++) {
          if (c1 > mid + 1 - l || p - c1 > r - mid - 1) continue;
          (dp[l][r][p] =
               max((dp[l][r][p]), (dp[l][mid + 1][c1] + dp[mid + 1][r][p - c1] +
                                   c1 * (p - c1) * lcp[mid])));
        }
      }
    }
  }
  cout << dp[0][n][k] << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  pre();
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
}
