macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
trait Bisect: Copy {
    fn halve(self, other: Self) -> Self;
    fn section_end(self, other: Self) -> bool;
}
impl Bisect for usize {
    fn halve(self, other: Self) -> Self {
        if self > other {
            other + (self - other) / 2
        } else {
            self + (other - self) / 2
        }
    }
    fn section_end(self, other: Self) -> bool {
        (if self > other {
            self - other
        } else {
            other - self
        }) <= 1
    }
}
fn binary_search<T: Bisect, F: Fn(T) -> bool>(f: F, ok: T, err: T) -> T {
    let mut ok = ok;
    let mut err = err;
    while !ok.section_end(err) {
        let m = ok.halve(err);
        if f(m) {
            ok = m;
        } else {
            err = m;
        }
    }
    ok
}
fn main() {
    input! { n, m, mut ab: [(u64, u8); n], lr: [(u64, u64); m] };
    ab.sort();
    let eo = ab
        .iter()
        .rev()
        .scan(0, |acc, &(_a, b)| {
            let res = *acc != b;
            *acc = b;
            Some(res as usize)
        })
        .collect::<Vec<_>>()
        .into_iter()
        .rev()
        .collect::<Vec<_>>();
    let codes = lr
        .iter()
        .map(|&(l, r)| {
            let li = binary_search(|i| ab[i - 1].0 < l, 0, n + 1);
            let ri = binary_search(|i| ab[i - 1].0 <= r, 0, n + 1);
            (li, ri)
        })
        .collect::<Vec<_>>();
    let mut graph = vec![vec![]; n + 1];
    for (i, &(li, ri)) in codes.iter().enumerate() {
        if li != ri {
            graph[li].push((ri, i));
            graph[ri].push((li, i));
        }
    }
    let mut visited = vec![false; n + 1];
    let mut cut = vec![];
    let mut offable = true;
    for u in 0..n + 1 {
        let res = dfs(u, &graph, &eo, &mut visited, &mut cut);
        if u != 0 && res & 1 == 1 {
            offable = false;
        }
    }
    if offable {
        println!("{}", cut.len());
        cut.sort();
        for &c in &cut {
            print!("{} ", c);
        }
        println!("");
    } else {
        println!("-1");
    }
}
fn dfs(
    u: usize,
    graph: &Vec<Vec<(usize, usize)>>,
    eo: &Vec<usize>,
    visited: &mut Vec<bool>,
    cut: &mut Vec<usize>,
) -> usize {
    let mut acc = 0;
    if visited[u] {
        return 0;
    }
    visited[u] = true;
    for &(v, i) in &graph[u] {
        if !visited[v] {
            let res = dfs(v, graph, eo, visited, cut);
            if res & 1 == 1 {
                cut.push(i + 1);
            }
            acc += res;
        }
    }
    let x = if u == 0 { 0 } else { eo[u - 1] };
    acc + x
}


Measured memory_bytes: 43768