p,l:array[1..200]of longint;
z:array[1..200,1..200]of longint;
u:array[1..200]of boolean;
begin
read(n,m);
for i:=1 to n do
begin
read(e);
while e<>0 do
begin
z[i,e]:=1;inc(l[i]);inc(p[e]);read(e);
end;
end;
for i:=1 to m do
begin
min:=maxlongint;
for j:=1 to m do if (p[j]<min)and(p[j]<>0) then
begin
q:=j;min:=p[j];
end;
if min=maxlongint then
begin
writeln(i-1);exit;
end;
min:=maxlongint;
for j:=1 to n do if (l[j]<min)and(u[j]=false)and(z[j,q]=1) then
begin
min:=l[j];q1:=j;
end;
u[q1]:=true;p[q]:=0;
for j:=1 to n do if z[j,q]=1 then
begin z[j,q]:=0;dec(l[j]);end;
for j:=1 to m do if z[q1,j]=1 then
begin z[q1,j]:=0;dec(p[j]);end;
end;
writeln(m);
end.