# 2019-11-12 15:53:47(JST)

import sys

# import collections

# import math

# from string import ascii_lowercase, ascii_uppercase, digits

# from bisect import bisect_left as bi_l, bisect_right as bi_r

# import itertools

# from functools import reduce

# import operator as op

# from scipy.misc import comb # float

# import numpy as np 



def main():

    nm, *lines = sys.stdin.readlines()

    n, m = [int(x) for x in nm.split()]

    likes = [[int(x) for x in line.split()] for line in lines]

    menu = set(range(1, m+1))

    res = menu

    for i in range(n):

        res &= set(likes[i][1:])

    

    print((len(res)))



if __name__ == "__main__":

    main()

import sys



n, m = list(map(int, sys.stdin.readline().split()))

g = [[int(x) for x in sys.stdin.readline().split()[1:]] for _ in range(n)]



def main():

    res = set(range(1, m+1))

    for a in g:

        res &= set(a)

    

    return len(res)



if __name__ == '__main__':

    ans = main()

    print(ans)
# 2019-11-12 15:53:47(JST)
import sys

# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
def main():
    nm, *lines = sys.stdin.readlines()
    n, m = [int(x) for x in nm.split()]
    likes = [[int(x) for x in line.split()] for line in lines]
    menu = set(range(1, m + 1))
    res = menu
    for i in range(n):
        res &= set(likes[i][1:])
    print((len(res)))


if __name__ == "__main__":
    main()

import sys

n, m = list(map(int, sys.stdin.readline().split()))
g = [[int(x) for x in sys.stdin.readline().split()[1:]] for _ in range(n)]


def main():
    res = set(range(1, m + 1))
    for a in g:
        res &= set(a)
    return len(res)


if __name__ == "__main__":
    ans = main()
    print(ans)

-# 2019-11-12 15:53:47(JST) -# import collections -# import math -# from string import ascii_lowercase, ascii_uppercase, digits -# from bisect import bisect_left as bi_l, bisect_right as bi_r -# import itertools -# from functools import reduce -# import operator as op -# from scipy.misc import comb # float -# import numpy as np +n, m = list(map(int, sys.stdin.readline().split())) +g = [[int(x) for x in sys.stdin.readline().split()[1:]] for _ in range(n)] + + -    nm, *lines = sys.stdin.readlines() -    n, m = [int(x) for x in nm.split()] -    likes = [[int(x) for x in line.split()] for line in lines] -    menu = set(range(1, m + 1)) -    res = menu -    for i in range(n): -        res &= set(likes[i][1:]) -    print((len(res))) +    res = set(range(1, m + 1)) +    for a in g: +        res &= set(a) +    return len(res) -    main() +    ans = main() +    print(ans)