def resolve():
    N, M = list(map(int, input().split(" ")))
    loved = [0 for _ in range(M)]
    for i in range(N):
        _, *a = list(map(int, input().split(" ")))
        for food in a:
            loved[food-1] += 1
    print(len(list(filter(lambda x: x == N, loved))))
    

if '__main__' == __name__:
    resolve() def resolve():
    N, M = list(map(int, input().split(" ")))
    loved = [0 for _ in range(M)]
    for i in range(N):
        _, *a = list(map(int, input().split(" ")))
        for food in a:
            loved[food-1] += 1
    print(len(list(filter(lambda x: x == N, loved))))
     resolve 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 0 for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) 0 loved = [0 for _ in range(M)] loved [0 for _ in range(M)] for i in range(N):
        _, *a = list(map(int, input().split(" ")))
        for food in a:
            loved[food-1] += 1
     i range(N) range N _, *a = list(map(int, input().split(" "))) _ list(map(int, input().split(" "))) list map(int, input().split(" ")) map int input().split(" ") ().split () input split " " *a a for food in a:
            loved[food-1] += 1
     food a loved[food-1] += 1 loved[food-1] loved food-1 food 1 1 print(len(list(filter(lambda x: x == N, loved)))) print len(list(filter(lambda x: x == N, loved))) len list(filter(lambda x: x == N, loved)) list filter(lambda x: x == N, loved) filter lambda x: x == N x == N x N x loved if '__main__' == __name__:
    resolve() '__main__' == __name__ '__main__' __name__ resolve() resolve def resolve():
    N, M = list(map(int, input().split(" ")))
    loved = [0 for _ in range(M)]
    for i in range(N):
        _, *a = list(map(int, input().split(" ")))
        for food in a:
            loved[food-1] += 1
    print(len(list(filter(lambda x: x == N, loved))))
     def resolve():
    N, M = list(map(int, input().split(" ")))
    loved = [0 for _ in range(M)]
    for i in range(N):
        _, *a = list(map(int, input().split(" ")))
        for food in a:
            loved[food-1] += 1
    print(len(list(filter(lambda x: x == N, loved))))
     resolve
def resolve():
    N, M = list(map(int, input().split(" ")))
    loved = [0 for _ in range(M)]
    for i in range(N):
        _, *a = list(map(int, input().split(" ")))
        for food in a:
            loved[food-1] += 1
    print(len(list(filter(lambda x: x == N, loved))))
    

if '__main__' == __name__:
    resolve()