/*
能力有限,只能是用暴力写的,看大神们都是用字典树写的,时间大约是100+ms
而暴力的却要800+ms,差距还是不小的。有空需要恶补一下。
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define maxn 11111
using namespace std;
typedef long long ll;
int main()
{
char s[10010][35];
double d[9];
memset(s,0,sizeof(s));
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int ans=0;
for(int i=0;i<n;i++)
{
scanf("%s",s[i]);
}
int k;
for(int i=0;i<m;i++)
{
scanf("%d",&k);
char t[35];
memset(t,0,sizeof(t));
for(int j=0;j<k;j++)
{
double mi=0;
for(int v=0;v<=7;v++)
{
scanf("%lf",&d[v]);
mi+=d[v];
}
mi/=8.0;
//求出8个数的平均值,在平均值之上的是宽条形码,也就是1
//在平均值之下的是窄条形码,也就是0
int b=1,sum=0;
for(int v=7;v>=0;v--)
{
if(d[v]>mi)
sum+=b;
b*=2;
}
t[j]=sum;
}
//cout<<t<<endl;
for(int v=0;v<n;v++)
if(strstr(s[v],t)==s[v])//strstr函数返回子串在母串中匹配到的位置
{ //失匹返回null,等于s[v]说明是前缀
ans++;
}
}
printf("%d\n",ans);
}
return 0;
}