#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned u;

#define INF INT_MAX
#define MOD (1000000007)
#define PI arccos(-1)

#define pll pair<long long, long long>
#define mp make_pair

#define vll vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vp vector<pll>
#define pb push_back
#define all(v) v.begin(), v.end()
#define print_vect(v) for (auto it : v) cout << it << " ";

#define pq priority_queue<ll>
#define pqg priority_queue<ll, vll, greater<ll>>
#define set set<ll>
#define mset multiset<ll>
#define queue queue<ll>

ll add(ll a, ll b) { a += b; return a >= MOD ? a - MOD : a; }
ll sub(ll a, ll b) { a -= b; return a < 0 ? a + MOD : a; }
ll mul(ll a, ll b) { return (long long)(a) * (long long)(b) % MOD; }
 
void sadd(ll &a, ll b) { a = add(a, b); }
void ssub(ll &a, ll b) { a = sub(a, b); }
void smul(ll &a, ll b) { a = mul(a, b); }

ll nzs(ll a, ll b){ 
    return (a / __gcd(a, b)) * b; 
}

const ll N = 1e7 + 5;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m, slucaj = 0;
    cin >> n >> m;
    vp intervali(n);
    for(ll i = 0 ; i < n ; i++){
        cin >> intervali[i].first >> intervali[i].second;
        if(intervali[i].first != intervali[i].second){
            if(slucaj == 0) slucaj = 1;
        }
        if(intervali[i].second > 20){
            if(slucaj != 0) slucaj = 2;
        }
    }
    if(n <= 1000 && m <= 1000){
        for(ll i = 0 ; i < m ; i++){
            ll l, r, x;
            cin >> l >> r >> x;
            l--;
            r--;
            ll ans = 0;
            for(ll i = l ; i <= r ; i++){
                if(intervali[i].first <= x && intervali[i].second >= x){
                    ans++;
                }
            }
            cout << ans << "\n";
        }
        return 0;
    }
    if(slucaj == 0){
        map<ll, ll> mapa;
        for(ll i = 0 ; i < n ; i++){
            mapa[intervali[i].first] = i + 1;
        }

        for(ll i = 0 ; i < m ; i++){
            ll l, r, x;
            cin >> l >> r >> x;
            ll index = mapa[x];
            if(index >= l && index <= r){
                cout << 1 << "\n";
            }
            else{
                cout << 0 << "\n";
            }
        }
        return 0;
    }
    if(slucaj == 1){
        map<ll, vll> mapa;
        for(ll i = 0 ; i < n ; i++){
            for(ll j = intervali[i].first ; j <= intervali[i].second ; j++){
                mapa[j].push_back(i);
            }
        }
        for(ll i = 0 ; i < m ; i++){
            ll l, r, x;
            cin >> l >> r >> x;
            l--;
            r--;
            ll left = lower_bound(all(mapa[x]), l) - mapa[x].begin();
            ll right = upper_bound(all(mapa[x]), r) - mapa[x].begin();
            cout << right - left << "\n";
        }
        return 0;
    }
    else if(slucaj == 2){
        map<ll, vll> mapa;
        for(ll i = 0 ; i < n ; i++){
            for(ll j = intervali[i].first ; j <= intervali[i].second ; j++){
                mapa[j].push_back(i);
            }
        }
        for(ll i = 0 ; i < m ; i++){
            ll l, r, x;
            cin >> l >> r >> x;
            l--;
            r--;
            ll left = lower_bound(all(mapa[x]), l) - mapa[x].begin();
            ll right = upper_bound(all(mapa[x]), r) - mapa[x].begin();
            cout << right - left << "\n";
        }
        return 0;
    }
    return 0;
}