N,M = list(map(int,input().split()))

list = [list(map(int,input().split())) for x in range(N)]



#一列目削除

for i in range(0,N):

    list[i].pop(0)



stock = []



#解答が全リストにあるか探索

for i in range(0,N):

    for j in range(0,len(list[i])):

        cnt = 0

        for k in range(0,N):

            if list[i][j] in list[k]:

                cnt += 1

        if cnt == N:

            stock.append(list[i][j])



if N == 1:

    stock = list[i]



print((len(set(stock))))
N,M = list(map(int,input().split()))



M_kinds = set(range(1,M+1))



for i in range(N):

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

    M_kinds &= set(b)



print((len(M_kinds)))
N, M = list(map(int, input().split()))
list = [list(map(int, input().split())) for x in range(N)]
# 一列目削除
for i in range(0, N):
    list[i].pop(0)
stock = []
# 解答が全リストにあるか探索
for i in range(0, N):
    for j in range(0, len(list[i])):
        cnt = 0
        for k in range(0, N):
            if list[i][j] in list[k]:
                cnt += 1
        if cnt == N:
            stock.append(list[i][j])
if N == 1:
    stock = list[i]
print((len(set(stock))))

N, M = list(map(int, input().split()))
M_kinds = set(range(1, M + 1))
for i in range(N):
    a, *b = list(map(int, input().split()))
    M_kinds &= set(b)
print((len(M_kinds)))

-list = [list(map(int, input().split())) for x in range(N)] -# 一列目削除 -for i in range(0, N): -    list[i].pop(0) -stock = [] -# 解答が全リストにあるか探索 -for i in range(0, N): -    for j in range(0, len(list[i])): -        cnt = 0 -        for k in range(0, N): -            if list[i][j] in list[k]: -                cnt += 1 -        if cnt == N: -            stock.append(list[i][j]) -if N == 1: -    stock = list[i] -print((len(set(stock)))) +M_kinds = set(range(1, M + 1)) +for i in range(N): +    a, *b = list(map(int, input().split())) +    M_kinds &= set(b) +print((len(M_kinds)))