def resolve():
    N,M = map(int,input().split())
    S = set(range(1,M+1))
    
    for i in range(N):
        K,*A = map(int,input().split())
        S&=set(A)
    print(len(S))

resolve() def resolve():
    N,M = map(int,input().split())
    S = set(range(1,M+1))
    
    for i in range(N):
        K,*A = map(int,input().split())
        S&=set(A)
    print(len(S)) resolve N,M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M S = set(range(1,M+1)) S set(range(1,M+1)) set range(1,M+1) range 1 M+1 M 1 for i in range(N):
        K,*A = map(int,input().split())
        S&=set(A)
     i range(N) range N K,*A = map(int,input().split()) K map(int,input().split()) map int input().split() ().split () input split *A A S&=set(A) S set(A) set A print(len(S)) print len(S) len S resolve() resolve def resolve():
    N,M = map(int,input().split())
    S = set(range(1,M+1))
    
    for i in range(N):
        K,*A = map(int,input().split())
        S&=set(A)
    print(len(S)) def resolve():
    N,M = map(int,input().split())
    S = set(range(1,M+1))
    
    for i in range(N):
        K,*A = map(int,input().split())
        S&=set(A)
    print(len(S)) resolve
def resolve():
    N,M = map(int,input().split())
    S = set(range(1,M+1))
    
    for i in range(N):
        K,*A = map(int,input().split())
        S&=set(A)
    print(len(S))

resolve()