#include <bits/stdc++.h>
using namespace std;

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define mp make_pair
#define parll pair<ll,ll>
#define parii pair<int,int>
#define frs first
#define sec second
#define neparno(x) (x&1)
#define parno(x) (!neparno(x))
#define lowbit(x) (x&-x)
#define nzd __gcd
#define nzs(e1,e2) (e1/nzd(e1,e2))*e2
#define all(V) V.begin(),V.end()
#define fill(V,v) fill(all(V),v)
#define l_b(BRL,brl) lower_bound( BRL.begin(), BRL.end(), brl )-BRL.begin()-1
#define u_b(BRU,bru) upper_bound( BRU.begin(), BRU.end(), bru )-BRU.begin()
#define mxn 200002

ll n,m,U[mxn],D[mxn];
map <ll,vector<ll>> M;
vector <ll> B[21];

void Podzadatak1()
{
    ll l,r,x;
    while ( m-- )
    {
        cin >> l >> r >> x;
        ll br = 0;
        for ( ll i = l; i <= r; i++ )
        {
            if ( U[i] <= x && x <= D[i] )
            {
                br++;
            }
        }
        cout << br << "\n";
    }
}

void Podzadatak2()
{
    for ( ll i = 1; i <= n; i++ )
    {
        M[U[i]].push_back(i);
    }
    ll l,r,x;
    while ( m-- )
    {
        cin >> l >> r >> x;
        ll lb = lower_bound( M[x].begin(), M[x].end(), l )-M[x].begin()+1;
        if ( lb+1 < M[x].size() && M[x][lb+1] == l )
        {
            lb++;
        }
        ll ub = upper_bound( M[x].begin(), M[x].end(), r )-M[x].begin()+1;
        if ( ub-1 >= 0 && M[x][ub-1] == l )
        {
            ub++;
        }
        cout << ub-lb+1 << "\n";
    }
}

void Podzadatak4()
{
    for ( ll j = 0; j <= 20; j++ )
    {
        for ( ll i = 1; i <= n; i++ )
        {
            if ( D[i] <= j && j <= U[i] )
            {
                B[j].push_back(i);
            }
        }
    }

    ll l,r,x;
    while ( m-- )
    {
        cin >> l >> r >> x;
        ll lb = lower_bound( B[x].begin(), B[x].end(), l )-B[x].begin()+1;
        if ( lb+1 < B[x].size() && B[x][lb+1] == l )
        {
            lb++;
        }
        ll ub = upper_bound( B[x].begin(), B[x].end(), r )-B[x].begin()+1;
        if ( ub-1 >= 0 && B[x][ub-1] == l )
        {
            ub++;
        }
        cout << ub-lb+1 << "\n";
    }
}

int main()
{
    ios;

    cin >> n >> m;
    bool provera2=true,provera4=true;
    for ( ll i = 1; i <= n; i++ )
    {
        cin >> U[i] >> D[i];
        if ( U[i] != D[i] )
        {
            provera2 = false;
        }
        if ( D[i] > 20 )
        {
            provera4 = false;
        }
    }

    if ( n <= 1000 && m <= 1000 )
    {
        Podzadatak1();
        return 0;
    }
    if ( provera2 )
    {
        Podzadatak2();
        return 0;
    }
    if ( provera4 )
    {
        Podzadatak4();
        return 0;
    }
    ll l,r,x;
    while ( m-- )
    {
        cin >> l >> r >> x;
        cout << "0\n";
    }

    return 0;
}