program bm
    implicit none
    integer::N
    integer,allocatable,dimension(:)::A
    integer,allocatable,dimension(:,:)::x,y
    logical::check

    integer::ANS
    integer::i,j,k
    read*,N
    allocate(A(N))
    allocate(X(N,N-1),Y(N,N-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(.not.btest(i,x(j,k)-1).and.y(j,k)==1)check=.false.
            end do
        end do
        if(check)ans=max(ans,cnt(i))
    end do
    print"(i0)",ans
contains
integer function CNT(K)
integer::K
integer::i
CNT=0
do i=1,bit_size(K)
    if(btest(K,i-1))cnt=cnt+1
end do
end function
end program bm