import numpy as np
n,m = map(int,input().split())
k = np.zeros(n,dtype=int)
a = np.zeros((n,m),dtype=int)
for i in range(n):
    p = list(map(int, input().split()))
    k[i] = p[0]
    for j in range(1,len(p)):
        a[i][j-1] = p[j]
ans = np.zeros(n+m,dtype=int)
for i in range(n):
    for j in range(m):
        if a[i][j] != 0:
            s = a[i][j]-1
            ans[s] += 1
an = 0
for i in range(n+m):
    if ans[i] == n:
        an += 1
print(an) import numpy as np numpy n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m k = np.zeros(n,dtype=int) k np.zeros(n,dtype=int) np.zeros np zeros n dtype=int dtype int a = np.zeros((n,m),dtype=int) a np.zeros((n,m),dtype=int) np.zeros np zeros (n,m) n m dtype=int dtype int for i in range(n):
    p = list(map(int, input().split()))
    k[i] = p[0]
    for j in range(1,len(p)):
        a[i][j-1] = p[j] i range(n) range n p = list(map(int, input().split())) p list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split k[i] = p[0] k[i] k i p[0] p 0 for j in range(1,len(p)):
        a[i][j-1] = p[j] j range(1,len(p)) range 1 len(p) len p a[i][j-1] = p[j] a[i][j-1] [i] a i j-1 j 1 p[j] p j ans = np.zeros(n+m,dtype=int) ans np.zeros(n+m,dtype=int) np.zeros np zeros n+m n m dtype=int dtype int for i in range(n):
    for j in range(m):
        if a[i][j] != 0:
            s = a[i][j]-1
            ans[s] += 1 i range(n) range n for j in range(m):
        if a[i][j] != 0:
            s = a[i][j]-1
            ans[s] += 1 j range(m) range m if a[i][j] != 0:
            s = a[i][j]-1
            ans[s] += 1 a[i][j] != 0 a[i][j] [i] a i j 0 s = a[i][j]-1 s a[i][j]-1 a[i][j] [i] a i j 1 ans[s] += 1 ans[s] ans s 1 an = 0 an 0 for i in range(n+m):
    if ans[i] == n:
        an += 1 i range(n+m) range n+m n m if ans[i] == n:
        an += 1 ans[i] == n ans[i] ans i n an += 1 an 1 print(an) print an n,m = map(int,input().split()) map(int,input().split()) n k = np.zeros(n,dtype=int) np.zeros(n,dtype=int) k p = list(map(int, input().split())) list(map(int, input().split())) p ans = np.zeros(n+m,dtype=int) np.zeros(n+m,dtype=int) ans m = map(int,input().split()) map(int,input().split()) m an = 0 0 an s = a[i][j]-1 a[i][j]-1 s an += 1 1 an a = np.zeros((n,m),dtype=int) np.zeros((n,m),dtype=int) a
import numpy as np
n,m = map(int,input().split())
k = np.zeros(n,dtype=int)
a = np.zeros((n,m),dtype=int)
for i in range(n):
    p = list(map(int, input().split()))
    k[i] = p[0]
    for j in range(1,len(p)):
        a[i][j-1] = p[j]
ans = np.zeros(n+m,dtype=int)
for i in range(n):
    for j in range(m):
        if a[i][j] != 0:
            s = a[i][j]-1
            ans[s] += 1
an = 0
for i in range(n+m):
    if ans[i] == n:
        an += 1
print(an)