#include <bits/stdc++.h>
using namespace std;
int n, k;
int sol = 0;
int tsol = 0;
string PRO[2001];
char c[501];
int pref[2001][2001];
vector<int> picked;
int pickedcnt = 0;
void generatetest(int pos) {
  if (k - pickedcnt > n - pos) return;
  if (pickedcnt == k) {
    tsol = 0;
    for (int i = 0; i < k - 1; i++) {
      for (int j = 0; j < k; j++) {
        tsol += pref[picked[i]][picked[j]];
      }
    }
    if (tsol > sol) sol = tsol;
    return;
  }
  for (int i = pos; i < n; i++) {
    picked.push_back(i);
    pickedcnt++;
    generatetest(i + 1);
    picked.pop_back();
    pickedcnt--;
  }
}
int commonpref(string a, string b) {
  int ret = 0;
  for (int i = 0; i < a.length() && i < b.length(); i++) {
    if (a[i] != b[i]) break;
    ret++;
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%s", &c);
    PRO[i] = c;
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      pref[i][j] = commonpref(PRO[i], PRO[j]);
    }
  }
  generatetest(0);
  printf("%d\n", sol);
  return 0;
}
