program main
  implicit none
  integer :: n, i, j, res
  integer, allocatable :: x(:, :), y(:, :), a(:)
  logical, allocatable :: is_honest(:)
  read (*, *) n
  allocate (x(n, n), y(n, n), a(n), is_honest(n))
  do i = 1, n
    read (*, *) a(i)
    do j = 1, a(i)
      read (*, *) x(i, j), y(i, j)
    end do
  end do

  res = 0
  is_honest(:) = .false.  ! can be anything
  call dfs(0, is_honest)

  write (*, "(i0)") res

  contains

  recursive subroutine dfs(depth, is_honest)
    integer, intent(in) :: depth
    logical, intent(in) :: is_honest(n)
    logical :: is_honest_new(n)
    if (depth == n) then
      if (is_possible(is_honest)) then
        res = max(res, count(is_honest))
      end if
    else
      is_honest_new(:) = is_honest(:)
      is_honest_new(depth + 1) = .true.
      call dfs(depth + 1, is_honest_new)
      is_honest_new(depth + 1) = .false.
      call dfs(depth + 1, is_honest_new)
    end if
  end subroutine dfs

  logical function is_possible(is_honest)
    logical, intent(in) :: is_honest(n)
    is_possible = .true.
    do i = 1, n
      if (.not. is_honest(i)) cycle
      do j = 1, a(i)
        if (is_honest(x(i, j)) .neqv. (y(i, j) == 1)) is_possible = .false.
      end do
    end do
  end function is_possible
end program main
