#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
T &minn(T &a, T b) {
  if (b < a) a = b;
  return a;
}
template <class T>
T &maxx(T &a, T b) {
  if (a < b) a = b;
  return a;
}
int &madd(int &a, int b) {
  a += b;
  if (a >= 1000000009) a -= 1000000009;
  return a;
}
int &msub(int &a, int b) {
  a -= b;
  if (a < 0) a += 1000000009;
  return a;
}
int &mmult(int &a, int b) { return a = (long long)a * b % 1000000009; }
int mdiv(long long a, long long b, long long m) {
  a = (a % m + m) % m;
  b = (b % m + m) % m;
  if (a % b == 0) return a / b;
  return (a + m * mdiv(-a, m, b)) / b;
}
struct bor {
  bor *A[26];
  int AN[27];
  vector<int> D[26];
  int n;
  bor() {
    int i;
    for (i = (0); i < (26); ++i) A[i] = NULL, AN[i] = 0, D[i].clear();
    AN[26] = 0;
    n = 0;
  }
  void add(char *s) {
    ++n;
    if (*s == 0) return;
    int i, j = *s - 'a';
    for (i = (j + 1) - 1; i >= (0); --i) ++AN[i];
    if (A[j] == NULL) A[j] = new bor();
    A[j]->add(s + 1);
  }
  int fnd(int n) {
    if (n > AN[0]) n = AN[0];
    return fnd(n, 0);
  }
  int fnd(int n, int i) {
    if (n <= 1) return 0;
    if (A[i] == NULL) return fnd(n, i + 1);
    for (; D[i].size() <= n;) D[i].push_back(-1);
    int &res = D[i][n];
    if (res >= 0) return res;
    res = 0;
    int k;
    for (k = (max(0, n - AN[i + 1])); k < (min(A[i]->n, n) + 1); ++k)
      maxx(res, fnd(n - k, i + 1) + A[i]->fnd(k) + k * (k - 1) / 2);
    return res;
  }
};
int n, m;
char S[511];
int main() {
  int i, j, k;
  char c;
  int a, d;
  int ts;
  for (ts = 1; scanf("%"
                     "d",
                     &(n)) > 0;
       ++ts) {
    scanf(
        "%"
        "d",
        &(m));
    bor b;
    for (i = (0); i < (n); ++i)
      scanf(
          "%"
          "s",
          &(S)),
          b.add(S);
    int res = b.fnd(m);
    printf(
        "%"
        "d",
        (res));
    printf("\n"), firstout = 1;
  }
  return 0;
}
