! 2019.12.8
!
      program answer
      implicit none
      integer :: N
      integer,allocatable,dimension(:) :: A
      integer,allocatable,dimension(:,:) :: X,Y
      integer :: ans
      integer :: cn
      integer :: sm
      integer,allocatable,dimension(:) :: J
      integer :: M
      integer :: i,k
!
      read(*,*) N
      allocate(A(N),X(N,N),Y(N,N),J(N))
! initialization
      ans = 0
! read data
      do i=1,N
        read(*,*) A(i)
        do k=1,A(i)
          read(*,*) X(i,k),Y(i,k)
        end do
      end do
! generate array
      do M=1,2**N-1
        cn = 0
        call mk_array(J,N,M)
      lp:do i=1,N
          do k=1,A(i)
            if(J(i) == 1) then
              if(J(X(i,k)) /= Y(i,k)) then
                cn = 1
                exit lp
              end if
            end if
          end do
        end do lp
        if(cn == 0) then
          sm = 0
          do i=1,N
            sm = J(i) + sm
          end do
          if(ans < sm) ans = sm
        end if
!        write(*,*) sm,M,(J(i),i=1,N)
      end do
      write(*,*) ans
      end program answer
!------------------------------------------------
      subroutine mk_array(J,N,M)
!------------------------------------------------
      implicit none
      integer,intent(in) :: N,M
      integer,dimension(N),intent(inout) :: J
      integer :: i
      integer :: cyc
      integer :: aaa
      intrinsic mod
! initialization
      do i=1,N
        J(i) = 0
      end do
! 
      aaa = M
      cyc = 1
      do
        if(mod(aaa,2) == 1) then
          J(cyc) = 1
        else
          J(cyc) = 0
        end if
        cyc = cyc + 1
        aaa = aaa / 2
        if( aaa == 0) exit
      end do
      end subroutine mk_array