program HonestOrUnkind2
  implicit none
  integer xy(15,15),a(15)
  integer n,ans,i,j,x,y,bit
  logical ok
  read(*,*) n
  xy(:,:)=-1
  do i=1,n
     read(*,*) a(i)
     do j=1,a(i)
        read(*,*) x,y
        xy(i,x)=y
     end do
  end do
  do bit=1,ishft(1,n)-1
     ok=.true.
     iloop:do i=1,n
        if(iand(bit,ishft(1,i-1))==0) cycle
        do j=1,a(i)
           if((xy(i,j)/=-1).and.(iand(bit,ishft(i,j-1))/=xy(i,j))) then
              ok=.false.
              exit iloop
           end if
        end do
     end do iloop
     if(ok) then
        ans=max(ans,popcnt(bit))
     end if
  end do
  print*,ans
end program HonestOrUnkind2
