program Project1;
var
  a:array[1..100,1..100] of integer;
n,j,i,u,v:integer;
begin
      read(n);
      for i:=1 to n do  begin
          read(u,v)    ;
          for j:=1 to n do begin
              a[i,j]:=0;
              if (i=u) and (j=v) then
                    a[i,j]:=1;
              end;
      end;
      if n=2 then if (a[1,1]*a[2,2]=1) or (a[2,1]*a[1,2]=1) then  write('0') else write('1')
      else begin

        write('0');
        end;
      read(i);
  end.