n, m = map(int, input().split(" "))
switch = []
for i in range(m):
  switch.append(list(map(int, input().split(" "))))
poweron = list(map(int, input().split(" ")))

print(switch)
print(poweron)
count = 0
for i in range(m):
  temp = 0
  for j in range(n):
    if i in switch[1:]:
      temp += 1
  if temp == poweron[i]:
    count += 1
print(count)