def resolve():
    N, M = list(map(int, input().split()))
    l = []
    ls = list(range(1, M+1))

    for i in range(N):
        l = list(map(int, input().split()))
        ls = set(l[1:]).intersection(ls)
    print(len(ls))
    return

resolve() def resolve():
    N, M = list(map(int, input().split()))
    l = []
    ls = list(range(1, M+1))

    for i in range(N):
        l = list(map(int, input().split()))
        ls = set(l[1:]).intersection(ls)
    print(len(ls))
    return 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 l = [] l [] ls = list(range(1, M+1)) ls list(range(1, M+1)) list range(1, M+1) range 1 M+1 M 1 for i in range(N):
        l = list(map(int, input().split()))
        ls = set(l[1:]).intersection(ls)
     i range(N) range N l = list(map(int, input().split())) l list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ls = set(l[1:]).intersection(ls) ls set(l[1:]).intersection(ls) (l[1:]).intersection (l[1:]) set l[1:] l 1: 1 intersection ls print(len(ls)) print len(ls) len ls return resolve() resolve def resolve():
    N, M = list(map(int, input().split()))
    l = []
    ls = list(range(1, M+1))

    for i in range(N):
        l = list(map(int, input().split()))
        ls = set(l[1:]).intersection(ls)
    print(len(ls))
    return def resolve():
    N, M = list(map(int, input().split()))
    l = []
    ls = list(range(1, M+1))

    for i in range(N):
        l = list(map(int, input().split()))
        ls = set(l[1:]).intersection(ls)
    print(len(ls))
    return resolve
def resolve():
    N, M = list(map(int, input().split()))
    l = []
    ls = list(range(1, M+1))

    for i in range(N):
        l = list(map(int, input().split()))
        ls = set(l[1:]).intersection(ls)
    print(len(ls))
    return

resolve()