Problem:
Score: 600 points

Problem Statement

After being invaded by the Kingdom of AlDebaran, bombs are planted throughout our country, AtCoder Kingdom.

Fortunately, our military team called ABC has managed to obtain a device that is a part of the system controlling the bombs.

There are N bombs, numbered 1 to N, planted in our country. Bomb i is planted at the coordinate A_i. It is currently activated if B_i=1, and deactivated if B_i=0.

The device has M cords numbered 1 to M. If we cut Cord j, the states of all the bombs planted between the coordinates L_j and R_j (inclusive) will be switched - from activated to deactivated, and vice versa.

Determine whether it is possible to deactivate all the bombs at the same time. If the answer is yes, output a set of cords that should be cut.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9\ (1 \leq i \leq N)

A_i are pairwise distinct.

B_i is 0 or 1. (1 \leq i \leq N)

1 \leq M \leq 2 \times 10^5

1 \leq L_j \leq R_j \leq 10^9\ (1 \leq j \leq M)

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
:
A_N B_N
L_1 R_1
:
L_M R_M

Output

If it is impossible to deactivate all the bombs at the same time, print -1. If it is possible to do so, print a set of cords that should be cut, as follows:

k
c_1 c_2 \dots c_k

Here, k is the number of cords (possibly 0), and c_1, c_2, \dots, c_k represent the cords that should be cut. 1 \leq c_1 < c_2 < \dots < c_k \leq M must hold.

Sample Input 1

3 4
5 1
10 1
8 0
1 10
4 5
6 7
8 9

Sample Output 1

2
1 4

There are two activated bombs at the coordinates 5, 10, and one deactivated bomb at the coordinate 8.

Cutting Cord 1 switches the states of all the bombs planted between the coordinates 1 and 10, that is, all of the three bombs.

Cutting Cord 4 switches the states of all the bombs planted between the coordinates 8 and 9, that is, Bomb 3.

Thus, we can deactivate all the bombs by cutting Cord 1 and Cord 4.

Sample Input 2

4 2
2 0
3 1
5 1
7 0
1 4
4 7

Sample Output 2

-1

Cutting any set of cords will not deactivate all the bombs at the same time.

Sample Input 3

3 2
5 0
10 0
8 0
6 9
66 99

Sample Output 3

0

All the bombs are already deactivated, so we do not need to cut any cord.

Sample Input 4

12 20
536130100 1
150049660 1
79245447 1
132551741 0
89484841 1
328129089 0
623467741 0
248785745 0
421631475 0
498966877 0
43768791 1
112237273 0
21499042 142460201
58176487 384985131
88563042 144788076
120198276 497115965
134867387 563350571
211946499 458996604
233934566 297258009
335674184 555985828
414601661 520203502
101135608 501051309
90972258 300372385
255474956 630621190
436210625 517850028
145652401 192476406
377607297 520655694
244404406 304034433
112237273 359737255
392593015 463983307
150586788 504362212
54772353 83124235

Sample Output 4

5
1 7 8 9 11

If there are multiple sets of cords that deactivate all the bombs when cut, any of them can be printed.

Solution in Fortran (GNU Fortran 9.2.1) (judge verdict: Wrong Answer)

module mod_unweighted_graph
  implicit none
  type t_list
    integer, allocatable :: at(:, :)
  end type
  type unweighted_graph
    type(t_list), allocatable :: list(:)
  end type
  interface unweighted_graph
    module procedure :: newug0
  end interface unweighted_graph
contains
  type(unweighted_graph) function newug0(n, m, a, b, e, undirected) result(res)
    integer, intent(in) :: n, m, a(:), b(:), e(:)
    logical, optional, intent(in) :: undirected
    logical :: u
    integer :: c(n), i
    u = merge(undirected, .true., present(undirected))
    c = 0
    do i = 1, m
      c(a(i)) = c(a(i)) + 1
      if (u) c(b(i)) = c(b(i)) + 1
    end do
    allocate(res%list(n))
    do i = 1, n
      allocate(res%list(i)%at(c(i), 2))
    end do
    do i = m, 1, -1
      res%list(a(i))%at(c(a(i)), 1) = b(i)
      res%list(a(i))%at(c(a(i)), 2) = e(i)
      c(a(i)) = c(a(i)) - 1
      if (u) then
        res%list(b(i))%at(c(b(i)), 1) = a(i)
        res%list(b(i))%at(c(b(i)), 2) = e(i)
        c(b(i)) = c(b(i)) - 1
      end if
    end do
  end
end module mod_unweighted_graph
module mod_two_dim_merge_sort
  implicit none
  integer, private, parameter :: intkind = 4
contains
  logical function less(a, b) result(res)
    integer(intkind), intent(in) :: a(:), b(:)
    res = a(1) < b(1)
  end
  subroutine merge_sort(a)
    integer(intkind), intent(inout) :: a(:, :)
    integer :: n, m, l, i, u
    n = size(a, 1)
    m = n
    l = 1
    do while (m > 1)
      do i = 1, m / 2
        u = min(2 * i * l, n)
        call merger(a(2 * (i - 1) * l + 1:(2 * i - 1) * l, :), &
        a((2 * i - 1) * l + 1:u, :))
      end do
      l = 2 * l
      m = (m + 1) / 2
    end do
  end
  subroutine merger(a1, a2)
    integer(intkind), intent(inout) :: a1(:, :), a2(:, :)
    integer(intkind) :: a(size(a1, 1) + size(a2, 1), size(a1, 2))
    integer :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(a1, 1)
    n2 = size(a2, 1)
    do while (i1 <= n1 .and. i2 <= n2)
      if (less(a1(i1, :), a2(i2, :))) then
        a(i1 + i2 - 1, :) = a1(i1, :)
        i1 = i1 + 1
      else
        a(i1 + i2 - 1, :) = a2(i2, :)
        i2 = i2 + 1
       end if
    end do
    if (i1 <= n1) then
      a(i1 + i2 - 1:n1 + n2, :) = a1(i1:n1, :)
    else
      a(i1 + i2 - 1:n1 + n2, :) = a2(i2:n2, :)
    end if
    a1 = a(1:n1, :)
    a2 = a(n1 + 1:n1 + n2, :)
  end
end module mod_two_dim_merge_sort
program perils_in_parallel
  use mod_unweighted_graph
  use mod_two_dim_merge_sort
  implicit none
  integer :: n, m, cnt = 0, i, j, l, r, p
  integer :: a(100000, 2) = 0, x(200000, 3) = 0, y(200000, 1) = 0, z(100001) = 0
  logical :: used(100000) = .false.
  type(unweighted_graph) :: g
  read(*,*) n, m
  do i = 1, n
    read(*,*) a(i, :)
  end do
  call merge_sort(a(1:n, :))
  z(1) = a(1, 2)
  do i = 2, n
    z(i) = xor(a(i, 2), a(i - 1, 2))
  end do
  z(n + 1) = a(n, 2)
  do i = 1, m
    j = cnt + 1
    read(*,*) x(j, 1:2)
    x(j, 3) = i
    if (x(j, 1) > a(n, 1)) cycle
    if (x(j, 2) < a(1, 1)) cycle
    l = 0
    r = n
    do while (r - l > 1)
      p = (l + r) / 2
      if (x(j, 1) <= a(p, 1)) then
        r = p
      else
        l = p
      end if
    end do
    x(j, 1) = r
    l = 1
    r = n + 1
    do while (r - l > 1)
      p = (l + r) / 2
      if (x(j, 2) >= a(p, 1)) then
        l = p
      else
        r = p
      end if
    end do
    x(j, 2) = r
    if (x(j, 1) < x(j, 2)) cnt = cnt + 1
  end do
  m = cnt
  g = unweighted_graph(n + 1, m, x(1:m, 1), x(1:m, 2), x(1:m, 3))
  p = 0
  do i = 1, n + 1
    if (used(i)) cycle
    if (btest(dfs(g, i), 0)) then
      write(*,'(i0)') -1
      stop
    end if
  end do
  write(*,'(i0)') p
  if (p > 0) then
    call merge_sort(y(1:p, :))
    write(*,'(i0)',advance='no') y(1, 1)
    do i = 2, p
      write(*,'(x,i0)',advance='no') y(i, 1)
    end do
  end if
  write(*,*)
contains
  recursive integer function dfs(this, v) result(res)
    type(unweighted_graph), intent(in) :: this
    integer, intent(in) :: v
    integer :: i, u, tmp
    used(v) = .true.
    res = z(v)
    do i = 1, size(this%list(v)%at, 1)
      u = this%list(v)%at(i, 1)
      if (used(u)) cycle
      tmp = dfs(this, u)
      if (btest(tmp, 0)) then
        p = p + 1
        y(p, 1) = this%list(v)%at(i, 2)
      end if
      res = xor(res, tmp)
    end do
  end
end program perils_in_parallel