var i, j, k, m, n, vc, cc, l:integer;
    c, p, q, v, w:array [1..100] of integer;
    a:array [1..100, 1..100] of boolean;
    ch:boolean;

procedure solve;
begin
  vc:=0; l:=0;
  repeat
    repeat
      ch:=false;
      for i:=1 to n do
        if (p[i]=0) and (c[i]=cc) then begin
          inc (vc); v[vc]:=i;
          for j:=1 to n do if a[i, j] then dec (p[j]);
          p[i]:=-1; ch:=true;
        end;
    until not ch;
    cc:=1-cc; inc (l);
  until vc>=n;
end;

begin
  reset (input, 'exp.in'); rewrite (output, 'exp.out');
  read (n);
  for i:=1 to n do begin
    read (c[i], p[i]);
    for j:=1 to p[i] do begin read (k); a[k, i]:=true; end;
  end;
  q:=p; cc:=0; solve;
  m:=l; w:=v;
  p:=q; cc:=1; solve;
  if m<l then begin l:=m; v:=w end;
  writeln (l-1);
  for i:=1 to vc do write (v[i], ' ');
end.