{滑雪队 POI
平面图 搜索
Author: yangbohua
Time: 2011-03-23}
program nar;
var
list:array[0..5000] of longint;
map:array[0..50000] of longint;
b:array[0..5000] of boolean;
n,m,i,j,count,ans:longint;
bool:boolean;
procedure dfs(v:longint);
var
i:longint;
begin
i:=list[v];
while i<list[v+1] do
begin
if v=1 then bool:=false;
if bool then exit;
if map[i]=n then
begin
ans:=ans+1;
bool:=true;
end
else
if b[map[i]] then
begin
b[map[i]]:=false;
dfs(map[i]);
end;
inc(i);
end;
end;
begin
assign(input,'nar.in');
reset(input);
assign(output,'nar.out');
rewrite(output);
readln(n);
count:=0;
for i:=1 to n do
begin
read(m);
list[i]:=count+1;
for j:=1 to m do
begin
inc(count);
read(map[count]);
end;
end;
list[n+1]:=count+1;
fillchar(b,sizeof(b),true);
ans:=0;
dfs(1);
writeln(ans);
close(input);
close(output);
end.