I=lambda:list(map(int,input().split()))

n,m=I()

a=[]

for _ in[0]*n:a.extend(I()[1:])

print((sum(n==a.count(i+1)for i in range(m))))
n,m=list(map(int,input().split()))

print((len(set.intersection(*[set(input().split()[1:])for _ in[0]*n]))))
I = lambda: list(map(int, input().split()))
n, m = I()
a = []
for _ in [0] * n:
    a.extend(I()[1:])
print((sum(n == a.count(i + 1) for i in range(m))))

n, m = list(map(int, input().split()))
print((len(set.intersection(*[set(input().split()[1:]) for _ in [0] * n]))))

-I = lambda: list(map(int, input().split())) -n, m = I() -a = [] -for _ in [0] * n: -    a.extend(I()[1:]) -print((sum(n == a.count(i + 1) for i in range(m)))) +n, m = list(map(int, input().split())) +print((len(set.intersection(*[set(input().split()[1:]) for _ in [0] * n]))))