   program abc147c
      implicit none
      integer,allocatable,dimension(:,:)::x,y
      integer,allocatable,dimension(:)::a
      integer::n
      integer::i,j,k
      integer::ans
      logical::check

      ! btest(i,j)// logical function //if a bit is set at position 'j' in 'i', return TRUE ; otherwise FALSE

         read *, n
         allocate(a(n),x(n,n-1),y(n,n-1)  ! x(n人の,最大n-1個の証言)

         a=0; x=-1; y=-1
         do i=1,n
            read *, a(i)
            do j=1,a(i)
               read *, x(i,j),y(i,j)
            end do
         end do

         ans=0
         do i=0,2**n-1        ! 正直者,不親切のパターンを提示
            check=.true.
            do j=1,n
               if (.not. btest(i,j-1)) cycle           ! 提示で正直者なら次へ
               do k=1,a(j)
                  if ( btest(i,x(j,k)-1) .and. y(j,k)==0) check=.false.         ! if(提示では正直者 .and. 証言では否 )
                  if ( .not. btest(i,x(j,k)-1) .and. y(j,k)==1) check==.false.  ! if(提示では不親切 .and. 証言は正直者 )
               end do
            end do
            if (check) ans=max(ans,cnt(i))
         end do

         print *, ans
         stop

   contains
      function cnt(k)
         implicit none
         integer,intent(in)::k
         integer::cnt
         integer::i

            cnt=0
            do i=1,bit_size(k)
               if (btest(k,i-1)) cnt=cnt+1
            end do
            return
      end function cnt

   end program abc147c