from collections import defaultdict

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

s = []

for _ in range(n):

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

    s.append(a)

dd = defaultdict(int)

for l in s:

    for k in l:

        dd[k] += 1



print((sum(1 if v == n else 0 for k, v in list(dd.items()))))

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

s = set(range(1, m+1))

for _ in range(n):

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

    s &= set(a)

print((len(s)))
from collections import defaultdict

n, m = list(map(int, input().split()))
s = []
for _ in range(n):
    k, *a = list(map(int, input().split()))
    s.append(a)
dd = defaultdict(int)
for l in s:
    for k in l:
        dd[k] += 1
print((sum(1 if v == n else 0 for k, v in list(dd.items()))))

n, m = list(map(int, input().split()))
s = set(range(1, m + 1))
for _ in range(n):
    k, *a = list(map(int, input().split()))
    s &= set(a)
print((len(s)))

-from collections import defaultdict - -s = [] +s = set(range(1, m + 1)) -    s.append(a) -dd = defaultdict(int) -for l in s: -    for k in l: -        dd[k] += 1 -print((sum(1 if v == n else 0 for k, v in list(dd.items())))) +    s &= set(a) +print((len(s)))