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

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

ans = [0] * m



for i in range(n):

    for j in range(1, len(ka[i])):

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

            if ka[i][j] == k:

                ans[k-1] += 1

                break



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

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

ans = [0] * m



for i in range(n):

    for j in ka[i][1:]:

        ans[j-1] += 1



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

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

-    for j in range(1, len(ka[i])): -        for k in range(1, m + 1): -            if ka[i][j] == k: -                ans[k - 1] += 1 -                break +    for j in ka[i][1:]: +        ans[j - 1] += 1