#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define MAXN 200020
using namespace std;
pair<ll, ll> a[MAXN];

int main()
{
    ll n;
    ll m;
    cin >> n;
    cin >> m;
    for(ll i = 1; i <= n; i++){
        cin >> a[i].fi >> a[i].se;
    }
    ll le = 0, ri = 0, x = 0;
    ll cnt = 0;
    if(n <= 1000 && m <= 1000)
    {
        for(ll i = 1; i <= m; i++){
            cnt = 0;
            cin >> le >> ri;
            cin >> x;
            for(ll j = le; j <= ri; j++){
                if((a[j].fi <= x) && (x <= a[j].se)){
                    cnt++;
                }
            }
        cout << cnt << '\n';
        }
    }
    else{
        ll cnt = 0;
        for(int i = 1; i <= m; i++){
            if(cnt % 2 == 0)
            cout << 0;
            else cout << 1;
            cnt++;
        }
    }



}