#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
template<class T> inline void YES(T condition) { 
    if(condition) cout << "YES" << endl;
    else cout << "NO" << endl;
}
template<class T> inline void Yes(T condition) {
    if(condition) cout << "Yes" << endl;
    else cout << "No" << endl;
}
template<class T> T gcd(T a, T b) {
    if(a && b) { return gcd(min(a, b), max(a, b) % min(a, b)); }
    else { return a; }
}
template<class T> T lcm(T a, T b){
    return a / gcd(a, b) * b;
}
const int MOD = 2019;
long long qpow(long long a, long long b) {
    if (b == 0) return 1;
    long long res = 1;
    while (b) {
        if (b & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<PII> A(n);
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i].first >> A[i].second;
        x[i] = A[i].first;
    }
    sort(A.begin(), A.end());
    sort(x.begin(), x.end());
    vector<int> B(n + 1, 0);
    if (A[0].second == 1) B[0] = 1;
    for (int i = 0; i < n - 1; i++) {
        if (A[i].second != A[i + 1].second) {
            B[i + 1] = 1;
        }
    }
    if (A.back().second == 1) B.back() = 1;
    // cout << "B:" << B << endl;
    vector<int> L(m);
    vector<int> R(m);
    for (int i = 0; i < m; i++) cin >> L[i] >> R[i];
    vector<vector<int>> g(n + 1);
    vector<vector<int>> idx(n + 1);
    vector<int> visit(n + 1, 0);
    // cout << "x:" << x << endl;
    for (int i = 0; i < m; i++) {
        int l = lower_bound(x.begin(), x.end(), L[i]) - x.begin();
        int r = upper_bound(x.begin(), x.end(), R[i]) - x.begin();
        // if (l == r) continue;
        g[l].push_back(r);
        g[r].push_back(l);
        idx[l].push_back(i);
        idx[r].push_back(i);
        // cout << i << "------------" << L[i] << "-" << R[i] << ":" << endl;
        // cout << l << ":" << g[l] << endl;
        // cout << r << ":" << g[r] << endl;
        // cout << idx[l] << endl;
        // cout << idx[r] << endl;
        // cout << endl;
        // cout << i << ":" << l << "&" << r << endl;
    }
    vector<int> res;
    function<void(int)> dfs = [&] (int a) {
        // cout << "dfs ing..." << a << endl;
        visit[a] = 1;
        for (int i = 0; i < g[a].size(); i++) {
            int nxt = g[a][i];
            if (!visit[nxt]) {
                dfs(nxt);
                if (B[nxt] == 1) {
                    B[a] ^= 1;
                    res.push_back(idx[a][i]);
                }
                // cout << "visited " << nxt << B << endl;
            }
        }
    };
    for (int i = 0; i < n + 1; i++) {
        if (!visit[i]) {
            dfs(i);
            // cout << i << ":" << "B" << B << endl;
            if (B[i] == 1) {
                cout << -1 << '\n';
                return 0;
            }
        }
    }
    sort(res.begin(), res.end());
    cout << res.size() << endl;
    for (int i= 0 ; i < (int)res.size(); i++) {
        if (i > 0) cout << " ";
        cout << res[i] + 1;
    }
    cout << '\n';

    return 0;
}

Measured memory_bytes: 23164