def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n,m = i2()
ls = []
for _ in range(n):
	a = intl()
	a = a[1:]
	ls.append(a)

for i in range(n-1):
	tmp = []
	for j in ls[i]:
		for k in ls[i+1]:
			if j == k:
				tmp.append(j)
	ls[i+1] = tmp

print( len(ls[-1]) ) def i():
	return int(input()) i return int(input()) int(input()) int input() input def i2():
	return map(int,input().split()) i2 return map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split def s():
	return str(input()) s return str(input()) str(input()) str input() input def l():
	return list(input()) l return list(input()) list(input()) list input() input def intl():
	return list(int(k) for k in input().split()) intl return list(int(k) for k in input().split()) list(int(k) for k in input().split()) list int(k) int k n,m = i2() n i2() i2 m ls = [] ls [] for _ in range(n):
	a = intl()
	a = a[1:]
	ls.append(a) _ range(n) range n a = intl() a intl() intl a = a[1:] a a[1:] a 1: 1 ls.append(a) ls.append ls append a for i in range(n-1):
	tmp = []
	for j in ls[i]:
		for k in ls[i+1]:
			if j == k:
				tmp.append(j)
	ls[i+1] = tmp i range(n-1) range n-1 n 1 tmp = [] tmp [] for j in ls[i]:
		for k in ls[i+1]:
			if j == k:
				tmp.append(j)
	 j ls[i] ls i for k in ls[i+1]:
			if j == k:
				tmp.append(j)
	 k ls[i+1] ls i+1 i 1 if j == k:
				tmp.append(j)
	 j == k j k tmp.append(j) tmp.append tmp append j ls[i+1] = tmp ls[i+1] ls i+1 i 1 tmp print( len(ls[-1]) ) print len(ls[-1]) len ls[-1] ls -1 n,m = i2() i2() n ls = [] [] ls a = intl() intl() a a = a[1:] a[1:] a def intl():
	return list(int(k) for k in input().split()) def intl():
	return list(int(k) for k in input().split()) intl def i():
	return int(input()) def i():
	return int(input()) i def l():
	return list(input()) def l():
	return list(input()) l tmp = [] [] tmp def s():
	return str(input()) def s():
	return str(input()) s def i2():
	return map(int,input().split()) def i2():
	return map(int,input().split()) i2 m = i2() i2() m
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n,m = i2()
ls = []
for _ in range(n):
	a = intl()
	a = a[1:]
	ls.append(a)

for i in range(n-1):
	tmp = []
	for j in ls[i]:
		for k in ls[i+1]:
			if j == k:
				tmp.append(j)
	ls[i+1] = tmp

print( len(ls[-1]) )