#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N), B(N), L(M), R(M);
    vector<int> unzip;
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
        unzip.push_back(A[i]);
    }
    for (int i = 0; i < M; i++) cin >> L[i] >> R[i];
    unzip.push_back(2e9);
    sort(begin(unzip), end(unzip));
    unzip.erase(unique(begin(unzip), end(unzip)), end(unzip));
    map<int, int> zip;
    for (int i = 0; i < unzip.size(); i++) zip[unzip[i]] = i;
    vector<vector<pair<int, int>>> G(zip.size());
    for (int i = 0; i < M; i++) {
        auto s = lower_bound(begin(unzip), end(unzip), L[i]) - begin(unzip);
        auto t = upper_bound(begin(unzip), end(unzip), R[i]) - begin(unzip);
        if (s == t) continue;
        G[s].emplace_back(t, i);
        G[t].emplace_back(s, i);
    }
    vector<int> C(zip.size()), D(zip.size()), visited(zip.size());
    for (int i = 0; i < N; i++) {
        C[zip[A[i]]] = B[i];
    }
    for (int i = 0; i < zip.size(); i++) {
        D[i] = (i > 0 ? C[i - 1] : 0) ^ C[i];
    }
    vector<int> ans;
    function<int(int, int)> recur = [&](int node, int prev) -> int {
        if (visited[node]) return 0;
        visited[node] = 1;
        int sum = D[node];
        for (auto &p : G[node]) if (p.first != prev) {
            int t = recur(p.first, node);
            if (t) ans.push_back(p.second), sum ^= 1;
        }
        return sum;
    };
    for (int i = 0; i < N; i++) {
        if (visited[i]) continue;
        if (D[i]) {
            int t = recur(i, -1);
            if (t) { cout << -1 << '\n'; return 0; }
        }
    }
    sort(begin(ans), end(ans));
    cout << ans.size() << '\n';
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] + 1 << " \n"[i == ans.size() - 1];
    }
    return 0;
}
