#include <bits/stdc++.h>

#define xx first
#define yy second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mp make_pair
#define pb push_back
#define popb pop_back
#define ez {cout << "NO\n"; return;}

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef string str;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX=1e6+3;
int n, q;
pair<pii, int> d[MAX];
bool t2=1, t4=1;
map<int, vector<int>> mm;
vector<int> pr[25];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin >> n >> q;
    for(int i=0;i<n;++i){
        cin >> d[i].xx.xx >> d[i].xx.yy;
        d[i].yy=i;
        if(d[i].xx.xx!=d[i].xx.yy) t2=0;
        if(d[i].xx.yy>20) t4=0;
    }
    if(t2){
        for(int i=0;i<n;++i){
            mm[d[i].xx.xx].pb(d[i].yy);
        }
        for(auto it=mm.begin();it!=mm.end();it++){
            sort((it->yy).begin(), (it->yy).end());
            //cout << it->xx << ": ";
            //for(auto x : it->yy){
            //    cout << x+1 << " ";
            //}
            //cout << '\n';
        }

        while(q--){
            int l, r, x;
            cin >> l >> r >> x;
            l--; r--;
            int ll=lower_bound(mm[x].begin(), mm[x].end(), l)-mm[x].begin();
            int rr=upper_bound(mm[x].begin(), mm[x].end(), r)-mm[x].begin();
            //cout << "-> " << ll << " " << rr << "\n";
            cout << rr-ll << '\n';
        }

    }
    else if(t4){
        for(int i=0;i<n;++i){
            for(int j=d[i].xx.xx;j<=d[i].xx.yy;++j){
                pr[j].pb(d[i].yy);
            }
        }
        for(int i=0;i<20;++i){
            sort(pr[i].begin(), pr[i].end());
        }
        while(q--){
            int l, r, x;
            cin >> l >> r >> x;
            l--; r--;
            int ll=lower_bound(pr[x].begin(), pr[x].end(), l)-pr[x].begin();
            int rr=upper_bound(pr[x].begin(), pr[x].end(), r)-pr[x].begin();
            //cout << "-> " << ll << " " << rr << "\n";
            cout << rr-ll << '\n';

        }
    }
    else{
        while(q--){
            int l, r, x, res=0;
            cin >> l >> r >> x;
            l--; r--;
            for(int i=l;i<=r;++i){
                if(x>=d[i].xx.xx && x<=d[i].xx.yy) res++;
            }
            cout << res << '\n';
        }
    }


    return 0;
}