program cojs981;
const
maxn=210;
var
link:array[1..maxn]of longint;
v:array[1..maxn]of boolean;
a:array[1..maxn,1..maxn]of boolean;
n,m,x,i,ans:longint;
function dfs(p:longint):boolean;
var
i:longint;
begin
for i:=1 to m do
if a[p,i] and not v[i] then
begin
v[i]:=true;
if (link[i]=0)or dfs(link[i]) then
begin
link[i]:=p;
exit(true);
end;
end;
exit(false);
end;
begin
assign(input,'unique.in');reset(input);
assign(output,'unique.out');rewrite(output);
readln(n,m);
for i:=1 to n do
begin
read(x);
while x<>0 do
begin
a[i,x]:=true;
read(x);
end;
end;
for i:=1 to n do
begin
fillchar(v,sizeof(v),false);
if dfs(i) then inc(ans);
end;
writeln(ans);
close(input);close(output);
end.