#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <iostream>
#include <iomanip>
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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    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;
        ab_s[i].first;
    }
    sort(ab_s.begin(), ab_s.end());

    // 隣接リスト. {i, to}
    vector adjs(n + 1, vector<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;
        }
        adjs[l_].push_back({i, r_});
        adjs[r_].push_back({i, l_});
    }

    // 差分
    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];
    }

    vector used(n + 1, false);
    vector sol(m, false); // solution vector
    auto dfs = [&](auto self, int v) -> bool {
        used[v] = true;
        bool ret = dif[v];
        for (auto &[e, u] : adjs[v])
        {
            if (used[u])
            {
                continue;
            }
            bool s = self(self, u);
            sol[e] = s; // mod 2 なので符号は気にしなくてOK
            ret = ret ^ s;
        }
        return ret;
    };

    dfs(dfs, n); // 頂点nは別に扱う
    rep(v, n)
    {
        if (used[v])
        {
            continue;
        }
        if (dfs(dfs, v))
        {
            cout << -1 << "\n";
            return 0;
        }
    }

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

    return 0;
}


Measured memory_bytes: 18148