#include <bits/stdc++.h>

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second

namespace treap
{
	struct node
	{
		node *ch[2];
		int key, mn, id, prio, sz;

		node(int key, int id) : key(key), mn(key), id(id)
		{
			ch[0] = ch[1] = NULL;
			sz = 1;
			prio = rand();
		}
	};

	node* new_node(int key, int id)
	{
		return new node(key, id);
	}

	int size(node *u)
	{
		return u ? u->sz : 0;
	}

	int mn(node *u)
	{
		return u ? u->mn : (1<<30);
	}

	node* update(node *u)
	{
		if (u)
		{
			u->sz = size(u->ch[0]) + size(u->ch[1]) + 1;
			u->mn = min({ u->key, mn(u->ch[0]), mn(u->ch[1]) });
		}
		return u;
	}

	pair<node*, node*> split(node* u, int k)
	{// split for the kth first elements
		if (!u)
			return { u, u };

		if (size(u->ch[0]) >= k)
		{
			auto s = split(u->ch[0], k);
			u->ch[0] = s.second;
			return { s.first, update(u) };
		}

		auto s = split(u->ch[1], k - size(u->ch[0]) - 1);
		u->ch[1] = s.first;
		return { update(u), s.second };
	}

	node* merge(node *u, node *v)
	{
		if (!u || !v)
			return u ? u : v;

		if (u->prio > v->prio)
		{
			u->ch[1] = merge(u->ch[1], v);
			return update(u);
		}

		v->ch[0] = merge(u, v->ch[0]);
		return update(v);
	}

	pair<int, int> go(node *u)
	{
		int r = 1;
		while (true)
		{
			if (u->key == u->mn)
			{
				r += size(u->ch[0]);
				return { r, u->id };
			}
			if (mn(u->ch[1]) == u->mn)
			{
				r += size(u->ch[0]) + 1;
				u = u->ch[1];
				continue;
			}
			u = u->ch[0];
		}
		assert(0);
	}
};

template<typename T>
struct fenwick
{
    int n;
    vector<T> f;
    fenwick(int n) : n(n), f(n + 1) {}

    T query(int p)
    {
        T ret = 0;
        for (++p; p > 0; p -= p & -p)
            ret += f[p];
        return ret;
    }

    void update(int p, T x)
    {
        for (++p; p <= n; p += p & -p)
            f[p] += x;
    }
};

int main()
{
	#ifdef DGC
		freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a(n);
	for (auto &i : a) cin >> i.F >> i.S;
	sort(a.begin(), a.end());

	vector<pair<int, int>> q(m);
	vector<treap::node*> v(n+1, NULL);
	for (int l, r, id = 0; id < m; ++id)
	{
		cin >> l >> r;
		l = lower_bound(a.begin(), a.end(), make_pair(l, 0)) - a.begin();
		r = upper_bound(a.begin(), a.end(), make_pair(r, 1)) - a.begin() - 1;
		if (l <= r) v[l] = treap::merge(v[l], treap::new_node(r, id));
		q[id] = { l, r };
	}

	vector<int> b(n, -1), id(n);
	for (int i = 0; i < n; ++i)
	{
		while (v[i] != NULL)
		{
			int x = treap::mn(v[i]);
			if (x >= i) break;
			int k = treap::go(v[i]).F;
			auto s1 = treap::split(v[i], k);
			auto s2 = treap::split(s1.F, k-1);
			v[i] = treap::merge(s2.F, s1.S);
		}

		if (v[i] == NULL) continue;
		int x = treap::mn(v[i]);
		b[i] = x;
		id[i] = treap::go(v[i]).S;
		v[x+1] = treap::merge(v[x+1], v[i]);
	}


	vector<vector<int>> adj(n+1);
	for (int i = 0; i < n; ++i)
	{
		if (b[i] != -1)
			adj[b[i]+1].push_back(i);
		else
			adj[n].push_back(i);
	}

	int g = 0;
	vector<int> dt(n+1), ft(n+1);
	function<void(int)> dfs = [&](int u)
	{
		dt[u] = g++;
		for (auto v : adj[u]) dfs(v);
		ft[u] = g++;
	};
	dfs(n);

	fenwick<int> f(g);
	vector<int> dp(n+1);
	for (int i = 0; i < n; ++i)
	{
		if (i) dp[i] += dp[i-1];
		if (a[i].S != dp[i] % 2)
		{
			if (b[i] == -1)
			{
				cout << "-1\n";
				return 0;
			}
			++dp[i];
			--dp[b[i]+1];
			f.update(dt[i], +1);
			f.update(dt[b[i]+1], -1);
		}
	}

	vector<int> ans;
	for (int i = n-1; i >= 0; --i)
		if ((f.query(ft[i]) - f.query(dt[i] - 1)) & 1)
		{
			ans.push_back(id[i]);
			f.update(dt[q[id[i]].F], +1);
		}

	cout << ans.size() << "\n";
	sort(ans.begin(), ans.end());
	for (auto &i : ans)
		cout << i+1 << " \n"[&i==&ans.back()];

	return 0;
}


Measured memory_bytes: 24704