program honest_or_unkinf2
    implicit none
    integer(4):: i,j,k, ans
    integer(4):: n, a, x, y
    integer(4), allocatable:: testimony(:,:), assumption(:)
    logical:: is_satisfied

    read*, n
    allocate(testimony(n,n), assumption(n))
    testimony(:,:) = -1

    do i=1, n
        read*, a
        do j=1, a
            read*, x, y
            testimony(x,i) = y
        end do
    end do

    ! do i=1,n
    !     print*, testimony(:,i)
    ! end do
    ans = 0
    do i =0, lshift(1,n)-1
        assumption=0
        do j=1,n
            if (btest(i,j-1)) assumption(j) = 1
        end do
        ! print*, assumption(:)
        is_satisfied = .true.
        do j=1, n
            if (assumption(j) == 0) cycle
            do k=1, n
                if(testimony(k,j) == -1) cycle
                if(testimony(k,j) /= assumption(k)) is_satisfied = .false.
            end do
        end do
        if (is_satisfied) ans = max(ans, sum(assumption(:)))
    end do

    print*, ans
    
end program honest_or_unkinf2