#include <bits/stdc++.h>
const double pi = acos(-1.0), eps = 1e-9;
const int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};
const int MO = (int)(1e9 + 7);
using namespace std;
string s[2001];
int n, k, l[1001][1001];
int lcp(int a, int b) {
  int ret = 0;
  while (ret < min((int)((s[a]).size()), (int)((s[b]).size())) &&
         s[a][ret] == s[b][ret])
    ++ret;
  return ret;
}
int who[1001], ans;
void dfs(int dep, int get) {
  if (dep == n) {
    int ret = 0;
    if (get != k) return;
    for (int i = 1; i <= k; i++)
      for (int j = i + 1; j <= k; j++) ret += l[who[i]][who[j]];
    {
      if (ret > ans) ans = ret;
    };
    return;
  }
  dfs(dep + 1, get);
  who[get + 1] = dep + 1;
  dfs(dep + 1, get + 1);
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) l[i][j] = lcp(i, j);
  dfs(0, 0);
  cout << ans << endl;
}
