def resolve():
    N, M = map(int, input().split())
    K = []
    A = []
    ans = 0
    for _ in range(N):
        a = list(map(int, input().split()))
        K.append(a[0])
        A.append(a[1:])
    for i in range(M):
        count = 0
        for j in range(N):
            if i+1 in A[j]:
                count += 1
        if count == N:
            ans += 1
    print(ans)
resolve() def resolve():
    N, M = map(int, input().split())
    K = []
    A = []
    ans = 0
    for _ in range(N):
        a = list(map(int, input().split()))
        K.append(a[0])
        A.append(a[1:])
    for i in range(M):
        count = 0
        for j in range(N):
            if i+1 in A[j]:
                count += 1
        if count == N:
            ans += 1
    print(ans) resolve N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M K = [] K [] A = [] A [] ans = 0 ans 0 for _ in range(N):
        a = list(map(int, input().split()))
        K.append(a[0])
        A.append(a[1:])
     _ range(N) range N a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split K.append(a[0]) K.append K append a[0] a 0 A.append(a[1:]) A.append A append a[1:] a 1: 1 for i in range(M):
        count = 0
        for j in range(N):
            if i+1 in A[j]:
                count += 1
        if count == N:
            ans += 1
     i range(M) range M count = 0 count 0 for j in range(N):
            if i+1 in A[j]:
                count += 1
         j range(N) range N if i+1 in A[j]:
                count += 1
         i+1 in A[j] i+1 i 1 A[j] A j count += 1 count 1 if count == N:
            ans += 1
     count == N count N ans += 1 ans 1 print(ans) print ans resolve() resolve def resolve():
    N, M = map(int, input().split())
    K = []
    A = []
    ans = 0
    for _ in range(N):
        a = list(map(int, input().split()))
        K.append(a[0])
        A.append(a[1:])
    for i in range(M):
        count = 0
        for j in range(N):
            if i+1 in A[j]:
                count += 1
        if count == N:
            ans += 1
    print(ans) def resolve():
    N, M = map(int, input().split())
    K = []
    A = []
    ans = 0
    for _ in range(N):
        a = list(map(int, input().split()))
        K.append(a[0])
        A.append(a[1:])
    for i in range(M):
        count = 0
        for j in range(N):
            if i+1 in A[j]:
                count += 1
        if count == N:
            ans += 1
    print(ans) resolve
def resolve():
    N, M = map(int, input().split())
    K = []
    A = []
    ans = 0
    for _ in range(N):
        a = list(map(int, input().split()))
        K.append(a[0])
        A.append(a[1:])
    for i in range(M):
        count = 0
        for j in range(N):
            if i+1 in A[j]:
                count += 1
        if count == N:
            ans += 1
    print(ans)
resolve()