from collections import Counter



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



L = []

cnt = 0



for _ in range(n):

    tmp = input().split()

    a = tmp[1:]

    L.extend(a)

    

c = Counter(L)

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

    if v==n:

        cnt += 1

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

foods = [0] * m

for _ in range(n):

    k, *a = input().split()

    for food in a:

        foods[int(food)-1] += 1

        

print((foods.count(n)))

        
from collections import Counter

n, m = list(map(int, input().split()))
L = []
cnt = 0
for _ in range(n):
    tmp = input().split()
    a = tmp[1:]
    L.extend(a)
c = Counter(L)
for k, v in list(c.items()):
    if v == n:
        cnt += 1
print(cnt)

n, m = list(map(int, input().split()))
foods = [0] * m
for _ in range(n):
    k, *a = input().split()
    for food in a:
        foods[int(food) - 1] += 1
print((foods.count(n)))

-from collections import Counter - -L = [] -cnt = 0 +foods = [0] * m -    tmp = input().split() -    a = tmp[1:] -    L.extend(a) -c = Counter(L) -for k, v in list(c.items()): -    if v == n: -        cnt += 1 -print(cnt) +    k, *a = input().split() +    for food in a: +        foods[int(food) - 1] += 1 +print((foods.count(n)))