#include <bits/stdc++.h>
#define dbg(x) cout << #x << "=" << x << endl
#define eps 1e-8
#define pi acos(-1.0)
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<‘0‘||c>‘9‘)if(c==‘-‘)flag=-1;res=c-‘0‘;
while((c=getchar())>=‘0‘&&c<=‘9‘)res=res*10+c-‘0‘;res*=flag;
}
namespace _buff {
const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
if (ib == ie) {
ib = ibuf;
ie = ibuf + fread(ibuf, 1, BUFF, stdin);
}
return ib == ie ? -1 : *ib++;
}
}
int qread() {
using namespace _buff;
int ret = 0;
bool pos = true;
char c = getc();
for (; (c < ‘0‘ || c > ‘9‘) && c != ‘-‘; c = getc()) {
assert(~c);
}
if (c == ‘-‘) {
pos = false;
c = getc();
}
for (; c >= ‘0‘ && c <= ‘9‘; c = getc()) {
ret = (ret << 3) + (ret << 1) + (c ^ 48);
}
return pos ? ret : -ret;
}
int p, k;
string a, b;
string ss[15];
int sum[1000][1000];
int f[1000][1000];
int main()
{
read(p);read(k);
for ( int i = 1; i <= p; ++i ) {
cin >> b;
a += b;
}
int main_len = a.size();
int n;
read(n);
vector<int> len(n + 7);
for ( int i = 1; i <= n; ++i ) {
cin >> ss[i];
len[i] = ss[i].size();
}
for ( int i = 0; i < main_len; ++i ) {
for ( int j = i; j < main_len; ++j ) {//todo:枚举子段
for ( int k = i; k <= j; ++k ) {
int ok = 1;
for ( int z = 1; z <= n; ++z ) {
if(k + len[z] - 1 > j)
continue;
for ( int w = 0; w < len[z]; ++w ) {
if(w == len[z] - 1 && a[k + w] == ss[z][w]) {
ok = 0;
break;
}
if(a[k + w] != ss[z][w]) {
break;
}
}
if(!ok)
break;
}
if(!ok) {
sum[i][j]++;
}
}
}
}
// for ( int i = 0; i < main_len; ++i ) {
// for ( int j = 0; j < main_len; ++j ) {
// printf("sum[%d][%d]:%d\n",i, j, sum[i][j]);
// }
// }
for ( int i = 0; i < main_len; ++i ) {
f[i][1] = sum[0][i];
for ( int j = 0; j < i; ++j ) {
for ( int k = 2; k <= min(k, j + 1); ++k ) {
f[i][k] = max(f[i][k], f[j][k - 1] + sum[j + 1][i]);
}
}
}
cout << f[main_len - 1][k] << endl;
return 0;
}