# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
LikeL = []
for i in range(N):
    temp = list(map(int, input().split()))
    temp.pop(0)
    LikeL.append(temp)

ans = 0
for Mi in range(M):
    all = True
    for i in range(N):
        if not(Mi+1 in LikeL[i]):
            all = False
            break
    if all:
        ans += 1
print(ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M LikeL = [] LikeL [] for i in range(N):
    temp = list(map(int, input().split()))
    temp.pop(0)
    LikeL.append(temp) i range(N) range N temp = list(map(int, input().split())) temp list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split temp.pop(0) temp.pop temp pop 0 LikeL.append(temp) LikeL.append LikeL append temp ans = 0 ans 0 for Mi in range(M):
    all = True
    for i in range(N):
        if not(Mi+1 in LikeL[i]):
            all = False
            break
    if all:
        ans += 1 Mi range(M) range M all = True all True for i in range(N):
        if not(Mi+1 in LikeL[i]):
            all = False
            break
     i range(N) range N if not(Mi+1 in LikeL[i]):
            all = False
            break
     not(Mi+1 in LikeL[i]) Mi+1 in LikeL[i] Mi+1 Mi 1 LikeL[i] LikeL i all = False all False break if all:
        ans += 1 all ans += 1 ans 1 print(ans) print ans input = sys.stdin.readline sys.stdin.readline input N, M = map(int, input().split()) map(int, input().split()) N ans += 1 1 ans all = False False all M = map(int, input().split()) map(int, input().split()) M temp = list(map(int, input().split())) list(map(int, input().split())) temp ans = 0 0 ans LikeL = [] [] LikeL all = True True all
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
LikeL = []
for i in range(N):
    temp = list(map(int, input().split()))
    temp.pop(0)
    LikeL.append(temp)

ans = 0
for Mi in range(M):
    all = True
    for i in range(N):
        if not(Mi+1 in LikeL[i]):
            all = False
            break
    if all:
        ans += 1
print(ans)
