#include <bits/stdc++.h>
#define xx first
#define yy second
using namespace std;
int n, m;
pair<pair<int, int>, int>granice[200020], upiti[200020];
int prefiksne[200020][20];
vector<int>indeksi[200020];
int reez[200020];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin>>n>>m;
    bool st3=true, st2=true;
    for(int i=1; i<=n; i++)
    {
        cin>>granice[i].xx.xx>>granice[i].xx.yy;
        if(granice[i].xx.yy!=granice[i].xx.xx)st2=false;
        if(granice[i].xx.yy>20)st3=false;
        granice[i].yy=i;
    }
    for(int i=0; i<m; i++)
    {
        cin>>upiti[i].xx.xx>>upiti[i].xx.yy>>upiti[i].yy;
    }
    if(n<=1000 and m<=1000)
    {
        for(int i=0; i<m; i++)
        {
            for(int j=upiti[i].xx.xx; j<=upiti[i].xx.yy; j++)
            {
                if(granice[j].xx.xx<=upiti[i].yy and granice[j].xx.yy>=upiti[i].yy)reez[i]++;
            }
        }
        for(int i=0; i<m; i++)cout<<reez[i]<<"\n";
    }
    else if(st2)
    {
        for(int i=1; i<=n; i++)
        {
            indeksi[granice[i].xx.xx].push_back(i);
        }
        for(int i=0; i<m; i++)
        {
            int trazen=upiti[i].yy;
            int donja=lower_bound(indeksi[trazen].begin(), indeksi[trazen].end(), upiti[i].xx.xx)-indeksi[trazen].begin();
            int gornja=upper_bound(indeksi[trazen].begin(), indeksi[trazen].end(), upiti[i].xx.yy)-indeksi[trazen].begin();
            reez[i]=gornja-donja;
        }
        for(int i=0; i<m; i++)cout<<reez[i]<<"\n";
    }
    else if(st3)
    {
        for(int i=1; i<=n; i++)
        {
            for(int j=0; j<=20; j++)
            {
                prefiksne[i][j]=prefiksne[i-1][j];
                if(granice[i].xx.xx<=j and granice[i].xx.yy>=j)prefiksne[i][j]++;
            }
        }
        for(int i=0; i<m; i++)
        {
            if(upiti[i].yy>20)reez[i]=0;
            else
            {
                int l=upiti[i].xx.xx, r=upiti[i].xx.yy;
                reez[i]=prefiksne[r][upiti[i].yy]-prefiksne[l-1][upiti[i].yy];
            }
        }
        for(int i=0; i<m; i++)cout<<reez[i]<<"\n";
    }
    else
    {
        sort(granice+1, granice+1+m);
        for(int i=0; i<m; i++)
        {
            int l=0, r=n+1;
            while(l<=r)
            {
                int midd=(l+r)/2;
                if(granice[midd].xx.xx<=upiti[i].yy)l=midd+1;
                else r=midd-1;
            }
            if(granice[r].xx.xx>upiti[i].yy)r--;
            if(granice[r].yy<=upiti[i].xx.yy and granice[r].yy>=upiti[i].xx.xx and granice[r].xx.yy>=upiti[i].yy)reez[i]=1;
            else reez[i]=0;
        }
        for(int i=0; i<m; i++)cout<<reez[i]<<"\n";
    }
    return 0;
}