#include <iostream>
#include <string.h>
using namespace std;
struct tree
{
tree *next[128], *fail;
int state, flag;
};
tree sta[1005];
int indexx;
tree *root, *p;
inline void newn()
{
sta[indexx].fail = NULL;
sta[indexx].flag = 0;
sta[indexx].state = indexx;
for(int i = 0; i < 128; i ++) sta[indexx].next[i] = 0;
}
void init()
{
indexx = 0;
newn();
root = &sta[indexx ++];
}
void insert(char ch[])
{
int id, i = 0;
p = root;
while(ch[i])
{
id = ch[i];
if(p->next[id] == 0)
{
newn();
p->next[id] = &sta[indexx ++];
}
p = p->next[id];
i ++;
}
p->flag = 1;
}
tree *que[100001];
bool search(tree *q)
{
while(q != root)
{
if(q->flag) return true;
q = q->fail;
}
return false;
}
void get_fail()
{
int close = -1, open = 0, i, pass;
p = root; p->fail = root;
que[0] = root;
while(close < open)
{
p = que[++close];
tree *q = p;
pass = 0;
if(q->flag == 0) pass = search(q);
if(pass) q->flag = 1;
for(i = 0; i < 128; i ++)
{
if(p->next[i] == 0)
{
if(p == root) p->next[i] = root;
else p->next[i] = p->fail->next[i];
}
else
{
if(p == root) p->next[i]->fail = root;
else p->next[i]->fail = p->fail->next[i];
que[++open] = p->next[i];
}
}
}
}
char str[85];
int greedy()
{
gets(str);
int L = strlen(str), state, ans = 0;
state = 0;
for(int i = 0; i < L; i ++)
{
state = sta[state].next[str[i]]->state;
if(sta[state].flag)
{
state = 0;
ans ++;
}
}
return ans;
}
int n, m;
int main()
{
while(scanf("%d%d", &n, &m),n+m)
{
init();
char dg[16];
gets(dg);
for(int i = 0; i < n; i ++)
{
gets(dg);
insert(dg);
}
get_fail();
int ans = 0;
for(int i = 0; i < m; i ++) ans += greedy();
printf("%d\n", ans);
}
}