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

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

all_kind_of_food = [i for i in range(1, M + 1)]

check_for_foods = [i for i in range(1, M + 1)]

for i in range(N):

  for j in range(M):

    if all_kind_of_food[j] in check_for_foods and (not all_kind_of_food[j] in preferances[i]):

      check_for_foods.remove(all_kind_of_food[j])

print((len(check_for_foods)))

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

preferances = [set((input().split())[1:]) for _ in range(N)]

for i in range(N - 1):

  preferances[i + 1] = preferances[i] & preferances[i + 1]

print((len(preferances[-1])))

N, M = list(map(int, input().split()))
preferances = [list(map(int, input().split()))[1:] for _ in range(N)]
all_kind_of_food = [i for i in range(1, M + 1)]
check_for_foods = [i for i in range(1, M + 1)]
for i in range(N):
    for j in range(M):
        if all_kind_of_food[j] in check_for_foods and (
            not all_kind_of_food[j] in preferances[i]
        ):
            check_for_foods.remove(all_kind_of_food[j])
print((len(check_for_foods)))

N, _ = list(map(int, input().split()))
preferances = [set((input().split())[1:]) for _ in range(N)]
for i in range(N - 1):
    preferances[i + 1] = preferances[i] & preferances[i + 1]
print((len(preferances[-1])))

-N, M = list(map(int, input().split())) -preferances = [list(map(int, input().split()))[1:] for _ in range(N)] -all_kind_of_food = [i for i in range(1, M + 1)] -check_for_foods = [i for i in range(1, M + 1)] -for i in range(N): -    for j in range(M): -        if all_kind_of_food[j] in check_for_foods and ( -            not all_kind_of_food[j] in preferances[i] -        ): -            check_for_foods.remove(all_kind_of_food[j]) -print((len(check_for_foods))) +N, _ = list(map(int, input().split())) +preferances = [set((input().split())[1:]) for _ in range(N)] +for i in range(N - 1): +    preferances[i + 1] = preferances[i] & preferances[i + 1] +print((len(preferances[-1])))