#include<bits/stdc++.h>
using namespace std;
struct node {
int child[3];
int par, par_c;
int go[3]={-1,-1,-1};
int link=-1;
bool ends;
int sum_on_links=-1;
};
node aho[10100];
int nxt=1;
void add(string& s) {
int curr=0;
for(char c:s) {
if(!aho[curr].child[c-'0']) {
aho[curr].child[c-'0']=nxt++;
aho[aho[curr].child[c-'0']].par=curr;
aho[aho[curr].child[c-'0']].par_c=c-'0';
}
curr=aho[curr].child[c-'0'];
}
aho[curr].ends=true;
}
int go(int x, int c);
int get_link(int x) {
if(aho[x].link!=-1) return aho[x].link;
if(!x || !aho[x].par) return aho[x].link=0;
return aho[x].link=go(get_link(aho[x].par), aho[x].par_c);
}
int go(int x, int c) {
if(aho[x].go[c]!=-1) return aho[x].go[c];
if(aho[x].child[c]>0) return aho[x].go[c]=aho[x].child[c];
if(x==0) return aho[x].go[c]=0;
if(get_link(x)!=x) {
return aho[x].go[c]=go(get_link(x), c);
}
return aho[x].go[c]=0;
}
int sum(int x) {
if(x==0) return 0;
if(aho[x].sum_on_links!=-1) return aho[x].sum_on_links;
return aho[x].sum_on_links=(int)aho[x].ends+sum(get_link(x));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin>>n>>k;
assert(k<=5000);
int sum_len=0;
for(int i=0;i<n;++i) {
string s;
cin>>s;
add(s);
assert((sum_len+=s.size())<=10000);
}
for(int i=0;i<nxt;++i) {
sum(i);
}
vector<int> dp(nxt,-1e9);
dp[0]=0;
for(int i=0;i<k;++i) {
vector<int> ndp(nxt, -1e9);
for(int j=0;j<nxt;++j) {
for(int c=0;c<3;++c) {
int st=go(j, c);
ndp[st]=max(ndp[st], aho[st].sum_on_links+dp[j]);
}
}
ndp.swap(dp);
}
cout<<*max_element(dp.begin(), dp.end())<<"\n";
}