import math
def main():
  n,m = list(map(int,input().split()))
  alist=[[]]
  for i in range(0,n):
    alist.append(list(map(int,input().split())))
  ans=set(alist[1][1:])
  for i in range(2,n+1):
    ans=ans & set(alist[i][1:])
  print(len(ans))
main() import math math def main():
  n,m = list(map(int,input().split()))
  alist=[[]]
  for i in range(0,n):
    alist.append(list(map(int,input().split())))
  ans=set(alist[1][1:])
  for i in range(2,n+1):
    ans=ans & set(alist[i][1:])
  print(len(ans)) main n,m = list(map(int,input().split())) n list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split m alist=[[]] alist [[]] [] for i in range(0,n):
    alist.append(list(map(int,input().split())))
   i range(0,n) range 0 n alist.append(list(map(int,input().split()))) alist.append alist append list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split ans=set(alist[1][1:]) ans set(alist[1][1:]) set alist[1][1:] [1] alist 1 1: 1 for i in range(2,n+1):
    ans=ans & set(alist[i][1:])
   i range(2,n+1) range 2 n+1 n 1 ans=ans & set(alist[i][1:]) ans ans & set(alist[i][1:]) ans set(alist[i][1:]) set alist[i][1:] [i] alist i 1: 1 print(len(ans)) print len(ans) len ans main() main def main():
  n,m = list(map(int,input().split()))
  alist=[[]]
  for i in range(0,n):
    alist.append(list(map(int,input().split())))
  ans=set(alist[1][1:])
  for i in range(2,n+1):
    ans=ans & set(alist[i][1:])
  print(len(ans)) def main():
  n,m = list(map(int,input().split()))
  alist=[[]]
  for i in range(0,n):
    alist.append(list(map(int,input().split())))
  ans=set(alist[1][1:])
  for i in range(2,n+1):
    ans=ans & set(alist[i][1:])
  print(len(ans)) main
import math
def main():
  n,m = list(map(int,input().split()))
  alist=[[]]
  for i in range(0,n):
    alist.append(list(map(int,input().split())))
  ans=set(alist[1][1:])
  for i in range(2,n+1):
    ans=ans & set(alist[i][1:])
  print(len(ans))
main()