#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <vector>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <iostream>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, b, a) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

struct SolveIncidenceMat
{
    using F = bool; // 体はF_2
    struct Edge
    {
        bool is_dom;
        int index, cod;
        Edge(bool is_dom, int index, int cod)
            : is_dom(is_dom), index(index), cod(cod) {}
    };

    int n, m;
    vector<F> c;
    vector<vector<Edge>> adjs;

    vector<bool> used;
    vector<F> sol; // solution vector


    SolveIncidenceMat(int n, vector<pair<int, int>> const &edges, vector<F> const &c)
        : n(n), m(edges.size()), c(c), adjs(n), used(n, false), sol(m, 0)
    {
        rep(e, m)
        {
            auto [a, b] = edges[e];
            adjs[a].emplace_back(true, e, b);
            adjs[b].emplace_back(false, e, a);
        }
    }

    F dfs(int v)
    {
        used[v] = true;
        bool ret = c[v];
        for (auto &[b, e, u] : adjs[v])
        {
            if (used[u])
            {
                continue;
            }
            bool s = dfs(u);
            sol[e] = s;
            ret = ret ^ s;
        }
        return ret;
    }

    bool solve()
    {
        rep(v, n)
        {
            if (used[v])
            {
                continue;
            }
            if (dfs(v))
            {
                return false;
            }
        }

        return true;
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> ab_s(n);
    rep(i, n)
    {
        cin >> ab_s[i].first >> ab_s[i].second;
    }
    sort(ab_s.begin(), ab_s.end());

    vector edges(m, pair<int, int>());
    rep(i, m)
    {
        int l, r;
        cin >> l >> r;
        ++r;
        int l_ = lower_bound(ab_s.begin(), ab_s.end(), make_pair(l, -1)) - ab_s.begin();
        int r_ = lower_bound(ab_s.begin(), ab_s.end(), make_pair(r, -1)) - ab_s.begin();
        if (l_ == r_)
        { // 無駄な辺は無視
            continue;
        }
        edges[i] = {l_, r_};
    }

    // 差分
    vector dif(n + 1, false);
    transform(ab_s.begin(), ab_s.end(), dif.begin(),
              [](auto p) { return p.second == 1; });
    repd(i, n)
    {
        dif[i + 1] = dif[i + 1] ^ dif[i];
    }

    SolveIncidenceMat sim(n + 1, edges, dif);
    sim.dfs(n);
    if (not sim.solve())
    {
        cout << -1 << '\n';
        return 0;
    }

    int cnt = accumulate(sim.sol.begin(), sim.sol.end(), 0, [](int acc, bool x) {
        return acc + x;
    });
    cout << cnt << '\n';
    rep(i, m)
    {
        if (sim.sol[i])
        {
            cout << i + 1 << ' ';
        }
    }

    return 0;
}


Measured memory_bytes: 19464