import sys

import collections as c



input = sys.stdin.readline



def main():

    ans = 0

    N, M = list(map(int, input().split()))

    a = []

    for _ in range(N):

        a += list(map(int, input().split()))[1:]

    co = c.Counter(a)

    for k, v in list(co.items()):

        if v == N:

            ans += 1

    print(ans)



if __name__ == '__main__':

    main()
import sys



input = sys.stdin.readline



def main():

    ans = 0

    N, M = list(map(int, input().split()))

    f = set(range(1,M+1))

    for _ in range(N):

        a = set(list(map(int, input().split()))[1:])

        f.intersection_update(a)

    print((len(f)))



if __name__ == '__main__':

    main()
import sys
import collections as c

input = sys.stdin.readline


def main():
    ans = 0
    N, M = list(map(int, input().split()))
    a = []
    for _ in range(N):
        a += list(map(int, input().split()))[1:]
    co = c.Counter(a)
    for k, v in list(co.items()):
        if v == N:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline


def main():
    ans = 0
    N, M = list(map(int, input().split()))
    f = set(range(1, M + 1))
    for _ in range(N):
        a = set(list(map(int, input().split()))[1:])
        f.intersection_update(a)
    print((len(f)))


if __name__ == "__main__":
    main()

-import collections as c -    a = [] +    f = set(range(1, M + 1)) -        a += list(map(int, input().split()))[1:] -    co = c.Counter(a) -    for k, v in list(co.items()): -        if v == N: -            ans += 1 -    print(ans) +        a = set(list(map(int, input().split()))[1:]) +        f.intersection_update(a) +    print((len(f)))