program homest_or_unkind2
    implicit none
    integer(4):: n, a, i, j, x, y, k,ans
    integer(4), allocatable::s(:,:), jd(:)
    logical:: ok

    read*, n
    allocate(s(n,n), jd(n))
    s(:,:) = -1

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

    ans = 0

    do i=1, lshift(1,n-1)

        jd(:) = 0

        do j=1,n
            if (and(rshift(i,j-1),1) == 1) jd(j) = 1
        end do

        ok = .true.
        
        do j=1,n
            if (jd(j) /= 1) cycle
            do k=1, n
                if (s(k,j) == -1) cycle
                if (s(k,j) /= jd(k)) ok = .false.
            end do
        end do
        if (ok) ans = max(ans, bit_count(i))
    end do

    print*, ans
contains
function bit_count(x) result(y)
    integer(4):: x, y, cx

    cx=x
    y=0

    do while(cx > 0)
        if (and(cx,1) == 1) y=y+1
        cx = rshift(cx,1)
    end do
end function
end program homest_or_unkind2