# abc118_b.py
# https://atcoder.jp/contests/abc118/tasks/abc118_b

# B - Foods Loved by Everyone /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# カツサンドくんはオムライスが好きです。
# 他にも明太子や寿司、クリームブリュレやテンダーロインステーキなどが好きで、これらの食べ物は全て、誰もが好きだと信じています。
# その仮説を証明するために、N人の人に M種類の食べ物について好きか嫌いかの調査を行いました。
# 調査の結果、i番目の人は Ai1 番目, Ai2 番目, ..., AiKi番目の食べ物だけ好きだと答えました。
# N人全ての人が好きだと答えた食べ物の種類数を求めてください。

# 制約
#     入力は全て整数である。
#     1≤N,M≤30
#     1≤Ki≤M
#     1≤Aij≤M
#     各 i(1≤i≤N) について Ai1,Ai2,...,AiKiは全て異なる。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N M
# K1 A11 A12 ... A1K1
# K2 A21 A22 ... A2K2
# :
# KN AN1 AN2 ... ANKN

# 出力
# N人全ての人が好きだと答えた食べ物の種類数を出力せよ。

# 入力例 1
# 3 4
# 2 1 3
# 3 1 2 3
# 2 3 2

# 出力例 1
# 1

# 3人全員が好きだと答えた食べ物は 3 番目の食べ物だけなので 1を出力します。

# 入力例 2
# 5 5
# 4 2 3 4 5
# 4 1 3 4 5
# 4 1 2 4 5
# 4 1 2 3 5
# 4 1 2 3 4

# 出力例 2
# 0

# カツサンドくんの仮説は全く正しくありませんでした。

# 入力例 3
# 1 30
# 3 5 10 30

# 出力例 3
# 3


def calculation(lines):
    # line = lines[0]
    # N = int(lines[0])
    N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i+1]))
    valueses = list()
    for i in range(N):
        valueses.append(list(map(int, lines[i+1].split())))

    dic = dict()
    for values in valueses:
        for i in range(1, len(values)):
            value = values[i]
            if value not in dic.keys():
                dic[value] = 1
            else:
                dic[value] += 1

    result = 0
    for key in dic:
        if dic[key] == N:
            result += 1

    return [result]


# 引数を取得
def get_input_lines():
    line = input()
    N, M = list(map(int, line.split()))
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3 4', '2 1 3', '3 1 2 3', '2 3 2']
        lines_export = [1]
    if pattern == 2:
        lines_input = ['5 5', '4 2 3 4 5', '4 1 3 4 5', '4 1 2 4 5', '4 1 2 3 5', '4 1 2 3 4']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['1 30', '3 5 10 30']
        lines_export = [3]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main() def calculation(lines):
    # line = lines[0]
    # N = int(lines[0])
    N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i+1]))
    valueses = list()
    for i in range(N):
        valueses.append(list(map(int, lines[i+1].split())))

    dic = dict()
    for values in valueses:
        for i in range(1, len(values)):
            value = values[i]
            if value not in dic.keys():
                dic[value] = 1
            else:
                dic[value] += 1

    result = 0
    for key in dic:
        if dic[key] == N:
            result += 1

    return [result]


# 引数を取得 calculation N, M = list(map(int, lines[0].split())) N list(map(int, lines[0].split())) list map(int, lines[0].split()) map int lines[0].split() [0].split [0] lines 0 split M valueses = list() valueses list() list for i in range(N):
        valueses.append(list(map(int, lines[i+1].split())))

     i range(N) range N valueses.append(list(map(int, lines[i+1].split()))) valueses.append valueses append list(map(int, lines[i+1].split())) list map(int, lines[i+1].split()) map int lines[i+1].split() [i+1].split [i+1] lines i+1 i 1 split dic = dict() dic dict() dict for values in valueses:
        for i in range(1, len(values)):
            value = values[i]
            if value not in dic.keys():
                dic[value] = 1
            else:
                dic[value] += 1

     values valueses for i in range(1, len(values)):
            value = values[i]
            if value not in dic.keys():
                dic[value] = 1
            else:
                dic[value] += 1

     i range(1, len(values)) range 1 len(values) len values value = values[i] value values[i] values i if value not in dic.keys():
                dic[value] = 1
            else:
                dic[value] += 1

     value not in dic.keys() value dic.keys() dic.keys dic keys dic[value] = 1 dic[value] dic value 1 dic[value] += 1 dic[value] dic value 1 result = 0 result 0 for key in dic:
        if dic[key] == N:
            result += 1

     key dic if dic[key] == N:
            result += 1

     dic[key] == N dic[key] dic key N result += 1 result 1 return [result] [result] result lines lines def get_input_lines():
    line = input()
    N, M = list(map(int, line.split()))
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines


# テストデータ get_input_lines line = input() line input() input N, M = list(map(int, line.split())) N list(map(int, line.split())) list map(int, line.split()) map int line.split() line.split line split M lines = list() lines list() list lines.append(line) lines.append lines append line for _ in range(N):
        lines.append(input())
     _ range(N) range N lines.append(input()) lines.append lines append input() input return lines lines def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3 4', '2 1 3', '3 1 2 3', '2 3 2']
        lines_export = [1]
    if pattern == 2:
        lines_input = ['5 5', '4 2 3 4 5', '4 1 3 4 5', '4 1 2 4 5', '4 1 2 3 5', '4 1 2 3 4']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['1 30', '3 5 10 30']
        lines_export = [3]
    return lines_input, lines_export


# 動作モード判別 get_testdata if pattern == 1:
        lines_input = ['3 4', '2 1 3', '3 1 2 3', '2 3 2']
        lines_export = [1]
     pattern == 1 pattern 1 lines_input = ['3 4', '2 1 3', '3 1 2 3', '2 3 2'] lines_input ['3 4', '2 1 3', '3 1 2 3', '2 3 2'] '3 4' '2 1 3' '3 1 2 3' '2 3 2' lines_export = [1] lines_export [1] 1 if pattern == 2:
        lines_input = ['5 5', '4 2 3 4 5', '4 1 3 4 5', '4 1 2 4 5', '4 1 2 3 5', '4 1 2 3 4']
        lines_export = [0]
     pattern == 2 pattern 2 lines_input = ['5 5', '4 2 3 4 5', '4 1 3 4 5', '4 1 2 4 5', '4 1 2 3 5', '4 1 2 3 4'] lines_input ['5 5', '4 2 3 4 5', '4 1 3 4 5', '4 1 2 4 5', '4 1 2 3 5', '4 1 2 3 4'] '5 5' '4 2 3 4 5' '4 1 3 4 5' '4 1 2 4 5' '4 1 2 3 5' '4 1 2 3 4' lines_export = [0] lines_export [0] 0 if pattern == 3:
        lines_input = ['1 30', '3 5 10 30']
        lines_export = [3]
     pattern == 3 pattern 3 lines_input = ['1 30', '3 5 10 30'] lines_input ['1 30', '3 5 10 30'] '1 30' '3 5 10 30' lines_export = [3] lines_export [3] 3 return lines_input, lines_export return lines_input, lines_export lines_input lines_export pattern pattern def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理 get_mode import sys sys args = sys.argv args sys.argv sys argv if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
     len(args) == 1 len(args) len args 1 mode = 0 mode 0 mode = int(args[1]) mode int(args[1]) int args[1] args 1 return mode mode def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理 main import time time started = time.time() started time.time() time.time time time mode = get_mode() mode get_mode() get_mode if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

     mode == 0 mode 0 lines_input = get_input_lines() lines_input get_input_lines() get_input_lines lines_input, lines_export = get_testdata(mode) lines_input get_testdata(mode) get_testdata mode lines_export lines_result = calculation(lines_input) lines_result calculation(lines_input) calculation lines_input for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理 line_result lines_result print(line_result) print line_result if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def calculation(lines):
    # line = lines[0]
    # N = int(lines[0])
    N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i+1]))
    valueses = list()
    for i in range(N):
        valueses.append(list(map(int, lines[i+1].split())))

    dic = dict()
    for values in valueses:
        for i in range(1, len(values)):
            value = values[i]
            if value not in dic.keys():
                dic[value] = 1
            else:
                dic[value] += 1

    result = 0
    for key in dic:
        if dic[key] == N:
            result += 1

    return [result]


# 引数を取得 def calculation(lines):
    # line = lines[0]
    # N = int(lines[0])
    N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i+1]))
    valueses = list()
    for i in range(N):
        valueses.append(list(map(int, lines[i+1].split())))

    dic = dict()
    for values in valueses:
        for i in range(1, len(values)):
            value = values[i]
            if value not in dic.keys():
                dic[value] = 1
            else:
                dic[value] += 1

    result = 0
    for key in dic:
        if dic[key] == N:
            result += 1

    return [result]


# 引数を取得 calculation def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理 def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理 main def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3 4', '2 1 3', '3 1 2 3', '2 3 2']
        lines_export = [1]
    if pattern == 2:
        lines_input = ['5 5', '4 2 3 4 5', '4 1 3 4 5', '4 1 2 4 5', '4 1 2 3 5', '4 1 2 3 4']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['1 30', '3 5 10 30']
        lines_export = [3]
    return lines_input, lines_export


# 動作モード判別 def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3 4', '2 1 3', '3 1 2 3', '2 3 2']
        lines_export = [1]
    if pattern == 2:
        lines_input = ['5 5', '4 2 3 4 5', '4 1 3 4 5', '4 1 2 4 5', '4 1 2 3 5', '4 1 2 3 4']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['1 30', '3 5 10 30']
        lines_export = [3]
    return lines_input, lines_export


# 動作モード判別 get_testdata def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理 def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理 get_mode def get_input_lines():
    line = input()
    N, M = list(map(int, line.split()))
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines


# テストデータ def get_input_lines():
    line = input()
    N, M = list(map(int, line.split()))
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines


# テストデータ get_input_lines
# abc118_b.py
# https://atcoder.jp/contests/abc118/tasks/abc118_b

# B - Foods Loved by Everyone /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# カツサンドくんはオムライスが好きです。
# 他にも明太子や寿司、クリームブリュレやテンダーロインステーキなどが好きで、これらの食べ物は全て、誰もが好きだと信じています。
# その仮説を証明するために、N人の人に M種類の食べ物について好きか嫌いかの調査を行いました。
# 調査の結果、i番目の人は Ai1 番目, Ai2 番目, ..., AiKi番目の食べ物だけ好きだと答えました。
# N人全ての人が好きだと答えた食べ物の種類数を求めてください。

# 制約
#     入力は全て整数である。
#     1≤N,M≤30
#     1≤Ki≤M
#     1≤Aij≤M
#     各 i(1≤i≤N) について Ai1,Ai2,...,AiKiは全て異なる。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N M
# K1 A11 A12 ... A1K1
# K2 A21 A22 ... A2K2
# :
# KN AN1 AN2 ... ANKN

# 出力
# N人全ての人が好きだと答えた食べ物の種類数を出力せよ。

# 入力例 1
# 3 4
# 2 1 3
# 3 1 2 3
# 2 3 2

# 出力例 1
# 1

# 3人全員が好きだと答えた食べ物は 3 番目の食べ物だけなので 1を出力します。

# 入力例 2
# 5 5
# 4 2 3 4 5
# 4 1 3 4 5
# 4 1 2 4 5
# 4 1 2 3 5
# 4 1 2 3 4

# 出力例 2
# 0

# カツサンドくんの仮説は全く正しくありませんでした。

# 入力例 3
# 1 30
# 3 5 10 30

# 出力例 3
# 3


def calculation(lines):
    # line = lines[0]
    # N = int(lines[0])
    N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i+1]))
    valueses = list()
    for i in range(N):
        valueses.append(list(map(int, lines[i+1].split())))

    dic = dict()
    for values in valueses:
        for i in range(1, len(values)):
            value = values[i]
            if value not in dic.keys():
                dic[value] = 1
            else:
                dic[value] += 1

    result = 0
    for key in dic:
        if dic[key] == N:
            result += 1

    return [result]


# 引数を取得
def get_input_lines():
    line = input()
    N, M = list(map(int, line.split()))
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3 4', '2 1 3', '3 1 2 3', '2 3 2']
        lines_export = [1]
    if pattern == 2:
        lines_input = ['5 5', '4 2 3 4 5', '4 1 3 4 5', '4 1 2 4 5', '4 1 2 3 5', '4 1 2 3 4']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['1 30', '3 5 10 30']
        lines_export = [3]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()
