using CompLib.Util;
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    int N, M;

    // 爆弾
    Bomb[] Bombs;

    bool[] Diff;

    List<Code>[] Edges;
    List<int> Ans = new List<int>();
    bool[] Flag;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();

        Bombs = new Bomb[N];

        for (int i = 0; i < N; i++)
        {
            Bombs[i] = new Bomb(sc.NextInt(), sc.NextInt() == 1);
        }

        Array.Sort(Bombs, (a, b) => a.A.CompareTo(b.A));

        Edges = new List<Code>[N + 1];
        for (int i = 0; i <= N; i++)
        {
            Edges[i] = new List<Code>();
        }

        for (int i = 0; i < M; i++)
        {
            int l = sc.NextInt();
            int r = sc.NextInt();

            // l以上か?
            int lNg = -1;
            int lOk = N;

            while (lOk - lNg > 1)
            {
                int med = (lOk + lNg) / 2;

                if (Bombs[med].A >= l)
                {
                    lOk = med;
                }
                else
                {
                    lNg = med;
                }
            }

            // r以下か?
            int rOk = -1;
            int rNg = N;
            while (rNg - rOk > 1)
            {
                int med = (rOk + rNg) / 2;
                if (Bombs[med].A <= r)
                {
                    rOk = med;
                }
                else
                {
                    rNg = med;
                }
            }

            if (lOk == rNg) continue;
            Edges[lOk].Add(new Code(lOk, rNg, i + 1));
            Edges[rNg].Add(new Code(rNg, lOk, i + 1));
        }

        // 隣合う爆弾との状態が違うならtrue
        // コードを切るとdiff[r], diff[l]が反転する
        Diff = new bool[N + 1];

        for (int i = 0; i < N; i++)
        {
            if (i == 0)
            {
                Diff[i] = Bombs[i].B;
            }
            else
            {
                Diff[i] = Bombs[i - 1].B != Bombs[i].B;
            }
        }

        Diff[N] = Bombs[N - 1].B;

        // コードを l,rを結ぶ辺と考える

        // 連結成分で全域木を作る
        // 辺を見たとき子の頂点がtrueならそのコードを切る (diff[l],diff[r]を反転させる)
        // 木が全部falseにならなかったら-1

        Flag = new bool[N + 1];

        Ans = new List<int>();

        for (int i = 0; i <= N; i++)
        {
            if (Diff[i])
            {
                Search(i);
                if (Diff[i])
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
        }

        Ans.Sort();
        Console.WriteLine(Ans.Count);
        Console.WriteLine(string.Join(" ", Ans));
    }

    void Search(int pos)
    {
        Flag[pos] = true;
        foreach (var c in Edges[pos])
        {
            if (Flag[c.R]) continue;
            Search(c.R);
            // 切る
            if (Diff[c.R])
            {
                Diff[c.R] = false;
                Diff[pos] = !Diff[pos];
                Ans.Add(c.Index);
            }
        }
    }

    public static void Main(string[] args) => new Program().Solve();
}

struct Bomb
{
    public int A;
    public bool B;
    public Bomb(int a, bool b)
    {
        A = a;
        B = b;
    }
}

class Code
{
    public readonly int L, R, Index;
    public Code(int l, int r, int i)
    {
        L = l;
        R = r;
        Index = i;
    }
}

namespace CompLib.Util
{
    using System;
    using System.Linq;
    class Scanner
    {
        private int _index;
        private string[] _line;
        const char separator = ' ';

        public Scanner()
        {
            _index = 0;
            _line = new string[0];
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(separator);
                _index = 0;
            }
            return _line[_index++];
        }
        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(separator);
            _index = _line.Length;
            return _line;
        }
        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
    }
}

Measured memory_bytes: 56980