#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:200000000")
const double EPS = 1E-9;
const int INF = 1000000000;
const long long INF64 = (long long)1E18;
const double PI = 3.1415926535897932384626433832795;
string s[110000];
int n, k, z[110][110], dp[1100000];
char buf[110000];
int main() {
  scanf("%d%d\n", &n, &k);
  for (int i = 0; i < (int)(n); i++) {
    scanf("%s", buf);
    s[i] = buf;
  }
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(n); j++) {
      int ans = 0;
      while (ans < (int)s[i].size() && ans < (int)s[j].size() &&
             s[i][ans] == s[j][ans])
        ans++;
      z[i][j] = ans;
    }
  int res = 0;
  for (int msk = 1; msk < (1 << n); msk++) {
    int cur;
    for (int i = 0; i < (int)(n); i++)
      if (msk & (1 << i)) {
        cur = i;
        break;
      }
    int val = dp[msk ^ (1 << cur)], cnt = 0;
    for (int i = 0; i < (int)(n); i++)
      if ((msk & (1 << i)) && i != cur) {
        val += z[i][cur];
        cnt++;
      }
    if (cnt + 1 == k) res = max(res, val);
    dp[msk] = val;
  }
  cout << res << endl;
  return 0;
}
