import sys
import math
from collections import Counter
import itertools
import fractions
import datetime
from decimal import Decimal
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

N,M=MI()
KA=LLI(N)
like=[0]*M

for ka in KA:
    i = 0
    for a in ka:
        if i == 0:
            i += 1
            continue
        like[a-1] += 1

cnt = 0
for l in like:
    if l == N:
        cnt+=1
print(cnt)


 import sys sys import math math from collections import Counter import itertools itertools import fractions fractions import datetime datetime from decimal import Decimal def II(): return int(sys.stdin.readline()) II def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る MI def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る LI LI() for _ in range(rows_number) for _ in range(rows_number) _ range(rows_number) range rows_number for _ in range(rows_number) LI() LI def LLI(rows_number): return [LI() for _ in range(rows_number)] LLI rows_number rows_number def SR(): return sys.stdin.readline().rstrip() SR ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz' ascii_lowercase 'abcdefghijklmnopqrstuvwxyz' ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ascii_uppercase 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ' ascii_uppercase2 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ' p2D = lambda x: print(*x, sep="\n") p2D lambda x: print(*x, sep="\n") print(*x, sep="\n") print *x x sep="\n" sep "\n" x p2E = lambda x: print(''.join(x)) p2E lambda x: print(''.join(x)) print(''.join(x)) print ''.join(x) ''.join '' join x x p2S = lambda x: print(*x, sep=" ") p2S lambda x: print(*x, sep=" ") print(*x, sep=" ") print *x x sep=" " sep " " x N,M=MI() N MI() MI M KA=LLI(N) KA LLI(N) LLI N like=[0]*M like [0]*M [0] 0 M for ka in KA:
    i = 0
    for a in ka:
        if i == 0:
            i += 1
            continue
        like[a-1] += 1 ka KA i = 0 i 0 for a in ka:
        if i == 0:
            i += 1
            continue
        like[a-1] += 1 a ka if i == 0:
            i += 1
            continue
         i == 0 i 0 i += 1 i 1 continue like[a-1] += 1 like[a-1] like a-1 a 1 1 cnt = 0 cnt 0 for l in like:
    if l == N:
        cnt+=1 l like if l == N:
        cnt+=1 l == N l N cnt+=1 cnt 1 print(cnt) print cnt cnt+=1 1 cnt def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る LI p2E = lambda x: print(''.join(x)) lambda x: print(''.join(x)) p2E M=MI() MI() M KA=LLI(N) LLI(N) KA def II(): return int(sys.stdin.readline()) def II(): return int(sys.stdin.readline()) II ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ' ascii_uppercase2 cnt = 0 0 cnt def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI(rows_number): return [LI() for _ in range(rows_number)] LLI p2D = lambda x: print(*x, sep="\n") lambda x: print(*x, sep="\n") p2D i += 1 1 i ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ascii_uppercase def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る MI ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz' 'abcdefghijklmnopqrstuvwxyz' ascii_lowercase def SR(): return sys.stdin.readline().rstrip() def SR(): return sys.stdin.readline().rstrip() SR p2S = lambda x: print(*x, sep=" ") lambda x: print(*x, sep=" ") p2S like=[0]*M [0]*M like N,M=MI() MI() N i = 0 0 i
import sys
import math
from collections import Counter
import itertools
import fractions
import datetime
from decimal import Decimal
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

N,M=MI()
KA=LLI(N)
like=[0]*M

for ka in KA:
    i = 0
    for a in ka:
        if i == 0:
            i += 1
            continue
        like[a-1] += 1

cnt = 0
for l in like:
    if l == N:
        cnt+=1
print(cnt)



