program honest_or_unkind_2
  implicit none
  integer :: n, a, x, y, m = 0, t(15,15) = -1, u, i, j, k
  read(*,*) n
  do i = 1, n
    read(*,*) a
    do j = 1, a
      read(*,*) x, y
      t(i,x) = y
    end do
  end do
  u = lshift(1,n)-1
  do k = 0, u
    do i = 1, n
      do j = 1, n
        if (t(i,j) < 0) cycle
        if (btest(k,i-1)) then
          if (btest(k,j-1) .eqv. t(i,j) == 0) goto 100
        end if
      end do
    end do
    m = max(m,popcnt(k))
100 end do
  write(*,'(i0)') m
end program honest_or_unkind_2