

import collections



N, M = list(map(int, input().split()))

likes = []

for i in range(N):

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

    _ = x.pop(0)

    likes += x



col = collections.Counter(likes)

count = 0

for k, v in list(col.items()):

    if v == N:

        count += 1



print(count)


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

likes = [0] *  m



for i in range(n):

    k, *a = list(map(int, input().split()))

    for j in a:

        likes[j-1] += 1



count = 0

for i in likes:

    if i == n:

        count += 1



print(count)
import collections

N, M = list(map(int, input().split()))
likes = []
for i in range(N):
    x = list(map(int, input().split()))
    _ = x.pop(0)
    likes += x
col = collections.Counter(likes)
count = 0
for k, v in list(col.items()):
    if v == N:
        count += 1
print(count)

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

-import collections - -N, M = list(map(int, input().split())) -likes = [] -for i in range(N): -    x = list(map(int, input().split())) -    _ = x.pop(0) -    likes += x -col = collections.Counter(likes) +n, m = list(map(int, input().split())) +likes = [0] * m +for i in range(n): +    k, *a = list(map(int, input().split())) +    for j in a: +        likes[j - 1] += 1 -for k, v in list(col.items()): -    if v == N: +for i in likes: +    if i == n: