#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xx first
#define yy second
#define ff(i,s,f) for(int i=s;i<f;i++)
#define fb(i,s,f) for(int i=(s)-1;i>=f;i--)
#define ffi(i,s,f) for(int i=s;i<=f;i++)
#define fbi(i,s,f) for(int i=s;i>=f;i--)
#define srt(a) sort(a.begin(),a.end());
#define srtg(a,int) sort(a.begin(),a.end(),greater<int>())
#define lb(a,x) lower_bound(a.begin(),a.end(),x)
#define ub(a,x) upper_bound(a.begin(),a.end(),x)
#define fnd(a,x) find(a.begin(),a.end(),x)
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef string str;

const int maxn=2e5+10;

struct nd{
    int a,l,r;
};

array<nd,maxn> segtd[22];
array<nd,maxn> segtu[22];

int n,m;
int d[maxn];
int u[maxn];

void build(int *a,array<nd,maxn>* segt,int l=0,int r=n-1,int dub=0){
    if(l==r){
        segt[dub][l].a=a[l];
        return;
    }
    int mid=l+(r-l)/2;
    build(a,segt,l,mid,dub+1);
    build(a,segt,mid+1,r,dub+1);
    int pl=0,pr=0;
    auto vl=segt[dub+1].begin()+l;
    auto vr=segt[dub+1].begin()+mid+1;
    int vls=mid-l+1;
    int vrs=r-mid;
    int tren=l;
    while(pl<vls || pr<vrs){
        if(pl==vls){
            segt[dub][tren].a=(vr[pr].a);
            pr++;
        }else if(pr==vrs){
            segt[dub][tren].a=(vl[pl].a);
            pl++;
        }else{
            if(vl[pl].a<=vr[pr].a){
                segt[dub][tren].a=(vl[pl].a);
                pl++;
            }else{
                segt[dub][tren].a=(vr[pr].a);
                pr++;
            }
        }
        segt[dub][tren].l=int(pl)-1;
        segt[dub][tren].r=int(pr)-1;
        tren++;
    }
}

int iter=0;

int query(array<nd,maxn>* segt,int tl,int tr,int x,int l,int r=n-1,int dub=0){
    iter++;
    if(tl<=l && r<=tr){
        return x+1;
    }
    int mid=l+(r-l)/2;
    int ret=0;
    if(tl<=mid) ret+=query(segt,tl,tr,(x!=-1 ? segt[dub][l+x].l:-1),l,mid,dub+1);
    if(tr>mid) ret+=query(segt,tl,tr,(x!=-1 ? segt[dub][l+x].r:-1),mid+1,r,dub+1);
    return ret;
}

const bool test=false;
mt19937 rng(3423235); //3423235

int query(array<nd,maxn>* segt,int l,int r,int x){
    nd pom={x,0,0};
    int poz=upper_bound(segt[0].begin(),segt[0].begin()+n,pom,[](const nd &a,const nd &b){
        return a.a<b.a;    
    })-segt[0].begin()-1;
    return query(segt,l,r,poz,0);
}

void solve(){
    if(!test) cin>>n>>m;
    if(test) m=200000;
    if(test) n=200000;
    for(int i=0;i<n;i++){
        if(!test) cin>>d[i]>>u[i];
        if(test) d[i]=rng()%1000000001;
        if(test) u[i]=rng()%1000000001;
        if(d[i]>u[i]) swap(d[i],u[i]);
    }
    build(d,segtd);
    build(u,segtu);
    while(m--){
        int l,r,x;
        if(!test) cin>>l>>r>>x;
        if(test) l=rng()%n+1;
        if(test) r=rng()%n+1;
        if(l>r) swap(l,r);
        if(test) x=rng()%1000000001;
        l--; r--;
        cout<<query(segtd,l,r,x)-query(segtu,l,r,x-1)<<"\n";
    }
    //cout<<iter<<"\n";
}

int main(){
    ios;
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}