from functools import reduce



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

k = [list(map(int, input().split()))[1:] for _ in range(n)]



print((len(reduce(lambda a,b: a&b, [set(kk) for kk in k]))))

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



s = [0] * m



for i in range(n):

    a = list(map(int, input().split()))[1:]

    for x in a:

        s[x-1] += 1



ans = 0

for x in s:

    if x == n:

        ans += 1

print(ans)

from functools import reduce

n, m = list(map(int, input().split()))
k = [list(map(int, input().split()))[1:] for _ in range(n)]
print((len(reduce(lambda a, b: a & b, [set(kk) for kk in k]))))

n, m = list(map(int, input().split()))
s = [0] * m
for i in range(n):
    a = list(map(int, input().split()))[1:]
    for x in a:
        s[x - 1] += 1
ans = 0
for x in s:
    if x == n:
        ans += 1
print(ans)

-from functools import reduce - -k = [list(map(int, input().split()))[1:] for _ in range(n)] -print((len(reduce(lambda a, b: a & b, [set(kk) for kk in k])))) +s = [0] * m +for i in range(n): +    a = list(map(int, input().split()))[1:] +    for x in a: +        s[x - 1] += 1 +ans = 0 +for x in s: +    if x == n: +        ans += 1 +print(ans)