#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> P;

template <typename T>
struct Edge
{
    int to;
    T cost;
};

template <typename T>
struct WeightedGraph
{
    int n;
    vector<vector<Edge<T>>> g;
    
    WeightedGraph(int n) : n(n){
        g.resize(n);
    }
    
    void init(int n_){
        n = n_;
        g.resize(n_);
    }
    
    void add_edge(int from, int to, T cost){
        g[from].push_back((Edge<T>){to, cost});
    }
};

template <typename T>
struct WeightedTree
{
    int n;
    int root;
    vector<vector<Edge<T>>> t;
    vector<int> par;
    vector<int> dpt;
    vector<int> pcs;

    void init(WeightedGraph<T> &g, int root_){
        n = g.n;
        root = root_;
        t.resize(n);
        par.resize(n);
        dpt.resize(n);
        pcs.resize(n);
        fill(dpt.begin(), dpt.end(), -1);
        queue<int> que;
        par[root] = -1;
        dpt[root] = 0;
        pcs[root] = -1;
        que.push(root);
        while(que.size()){
            int pa = que.front();
            que.pop();
            for(Edge<T> e : g.g[pa]){
                int ch = e.to;
                if(dpt[ch] == -1){
                    t[pa].push_back(e);
                    par[ch] = pa;
                    dpt[ch] = dpt[pa] + 1;
                    pcs[ch] = e.cost;
                    que.push(ch);
                }
            }
        }
    }
    
    WeightedTree(){}
    
    WeightedTree(WeightedGraph<T> &g, int root_){
        init(g, root_);
    }
};

class UnionFind
{
    vector<int> par, rank;
    
public:
    UnionFind(int n){
        par.resize(n);
        rank.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int find(int i){
        if(i == par[i]) return i;
        return par[i] = find(par[i]);
    }
    
    bool same(int i, int j){
        return find(i) == find(j);
    }
    
    void unite(int i, int j){
        if(same(i, j)) return;
        i = find(i), j = find(j);
        if(rank[i] < rank[j]) par[i] = j;
        else{
            par[j] = i;
            if(rank[i] == rank[j]) rank[i]++;
        }
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    int a[100005], b[100005];
    P p[100005];
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        p[i] = P(a[i], b[i]);
    }
    sort(p, p + n);
    for(int i = 0; i < n; i++){
        a[i] = p[i].first;
        b[i] = p[i].second;
    }
    b[n] = 0;
    WeightedGraph<int> g(n + 2);
    UnionFind uf(n + 2);
    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        int u = lower_bound(a, a + n, l) - a;
        int v = upper_bound(a, a + n, r) - a;
        if(!uf.same(u, v)){
            g.add_edge(u, v, i);
            g.add_edge(v, u, i);
            uf.unite(u, v);
        }
    }
    int d[100005];
    fill(d, d + n + 1, -1);
    int k = 0;
    for(int i = 0; i <= n; i++){
        int u = uf.find(i);
        if(d[u] == -1){
            g.add_edge(u, n + 1, m);
            g.add_edge(n + 1, u, m);
            d[u] = k;
            k++;
        }
    }
    WeightedTree<int> t(g, n + 1);
    int s[100005];
    int c[100005]{0};
    fill(s, s + n + 1, -1);
    for(int i = 0; i <= n; i++){
        if((i == 0 && b[i] == 1) || b[i] != b[i - 1]){
            int u = uf.find(i);
            if(s[u] == -1) s[u] = i;
            else{
                c[i]++;
                c[s[u]]++;
                s[u] = -1;
            }
        }
    }
    for(int i = 0; i <= n; i++){
        if(s[i] != -1){
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i = 0; i <= n; i++){
        p[i] = P(t.dpt[i], i);
    }
    sort(p, p + n + 1, greater<P>());
    for(int i = 0; i <= n; i++){
        int u = p[i].second;
        c[t.par[u]] += c[u];
    }
    vector<int> ans;
    for(int i = 0; i <= n; i++){
        if(c[i] % 2) ans.push_back(t.pcs[i] + 1);
    }
    sort(ans.begin(), ans.end());
    cout << (int)ans.size() << endl;
    for(int x : ans) cout << x << " ";
    cout << endl;
}


Measured memory_bytes: 15996