#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
void mytimer(string task) {}
void ext(int c) {}
struct node {
  int go[26];
  char goc[26];
  int gol;
  int cnt;
};
node tr[2010 * 510];
int sz = 1;
void addw(const char *s) {
  int v = 0;
  for (int i = 0; s[i]; ++i) {
    int p = -1;
    for (int j = 0; j < (tr[v].gol); ++j) {
      if (tr[v].goc[j] == s[i]) {
        p = tr[v].go[j];
        break;
      }
    }
    if (p == -1) {
      p = tr[v].go[tr[v].gol] = sz++;
      tr[v].goc[tr[v].gol++] = s[i];
    }
    v = p;
  }
  ++tr[v].cnt;
}
vector<int> *dp = new vector<int>[2010 * 510];
void doit(int v) {
  dp[v].push_back(0);
  for (int i = 0; i < (tr[v].cnt); ++i) dp[v].push_back(0);
  for (int g = 0; g < (tr[v].gol); ++g) {
    int p = tr[v].go[g];
    doit(p);
    int s = (int)dp[p].size() - 1;
    dp[v].insert(dp[v].end(), s, -1000000000 * 2 - 10);
    for (int k = (int)dp[v].size() - s - 1; k >= 0; --k) {
      for (int i = 1; i <= s; ++i) {
        int t = dp[v][k] + dp[p][i] + i * (i - 1) / 2;
        if (t > dp[v][k + i]) dp[v][k + i] = t;
      }
    }
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  static char line[600];
  gets(line);
  for (int i = 0; i < (n); ++i) {
    gets(line);
    addw(line);
  }
  doit(0);
  cout << dp[0][k];
  return 0;
}
