n, m = list(map(int, input().split()))

k = [list(map(int, input().split())) for i in range(n)]

ans = 0

for i in range(1, m+1):

    cnt = 0

    for p in k:

        if i in p[1:]:

            cnt += 1

    if cnt == n:

        ans += 1

print(ans)
n,m = list(map(int,input().split()))

cnt = [0]*(m+1)

for i in range(n):

    x = list(map(int, input().split()))

    for p in x[1:]:

        cnt[p] += 1

print((cnt.count(n)))
n, m = list(map(int, input().split()))
k = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(1, m + 1):
    cnt = 0
    for p in k:
        if i in p[1:]:
            cnt += 1
    if cnt == n:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
cnt = [0] * (m + 1)
for i in range(n):
    x = list(map(int, input().split()))
    for p in x[1:]:
        cnt[p] += 1
print((cnt.count(n)))

-k = [list(map(int, input().split())) for i in range(n)] -ans = 0 -for i in range(1, m + 1): -    cnt = 0 -    for p in k: -        if i in p[1:]: -            cnt += 1 -    if cnt == n: -        ans += 1 -print(ans) +cnt = [0] * (m + 1) +for i in range(n): +    x = list(map(int, input().split())) +    for p in x[1:]: +        cnt[p] += 1 +print((cnt.count(n)))