using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace vaga
{
    internal class Program
    {
        static bool VagaMozeIzmeriti(int[] donja, int[] gornja, int indexVage1, int indexVage2, int tezina)
        {
            for (int i = indexVage1; i <= indexVage2; i++)
            {
                if ((tezina >= donja[i-1]) && (tezina <= gornja[i-1]))
                    return true;
            }
            return false;
        }
        static void Main(string[] args)
        {
            string[] s3 = Console.ReadLine().Split();
            int n = int.Parse(s3[0]);
            int m = int.Parse(s3[1]);

            int[] d = new int[n];
            int[] u = new int[n];

            string[] donjaIGornjaGranica = new string[n];

            for (int i = 0; i < n; i++)
            {
                string[] s1 = Console.ReadLine().Split();
                d[i] = int.Parse(s1[0]);
                u[i] = int.Parse(s1[1]);
            }

            int[] l = new int[m];
            int[] r = new int[m];
            int[] x = new int[m];

            for (int i = 0; i < m; i++)
            {
                string[] s2 = Console.ReadLine().Split();
                l[i] = int.Parse(s2[0]);
                r[i] = int.Parse(s2[1]);
                x[i] = int.Parse(s2[2]);
            }

            for (int i = 0; i < m; i++)
            {
                if(VagaMozeIzmeriti(d, u, l[i], r[i], x[i]))
                    Console.WriteLine(1);
                else
                    Console.WriteLine(0);
            }
        }
    }
}