#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int prviveci(int x, vector<int>a)
{
	int l = 0, d = a.size() - 1;
	while (l<=d)
	{
		int s = (l + d) / 2;
		if (a[s] > x) d = s - 1;
		else if (a[s] == x) return s;
		else l = s + 1;
	}
	return l;
}
int prvimanji(int x, vector<int>a)
{
	int l = 0, d = a.size() - 1;
	while (l <= d)
	{
		int s = (l + d) / 2;
		if (a[s] > x) d = s - 1;
		else if (a[s] == x) return s;
		else l = s + 1;
	}
	return d;
}
int main()
{
	int n, m; cin >> n >> m;
	bool isti = true, manjiod20 = true;
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].first >> a[i].second;
		if (a[i].first != a[i].second) isti = false;
		if (a[i].second > 20) manjiod20 = false;
	}
	if (n <= 1000 && m <= 1000)
	{
		for (int i = 0; i < m; i++)
		{
			int l, r, x; cin >> l >> r >> x;
			int br = 0;
			for (int j = l - 1; j < r; j++)
			{
				if (a[j].first <= x && a[j].second >= x) br++;
			}
			cout << br << endl;
		}
	}
	else if (isti)
	{
		map<int, vector<int>> b;
		for (int i = 0; i < n; i++)
		{
			b[a[i].first].push_back(i + 1);
		}
		for (int i = 0; i < m; i++)
		{
			int x, y, t; cin >> x >> y >> t;
			cout << prvimanji(y, b[t]) - prviveci(x, b[t]) + 1 << endl;
		}
	}
	else if (manjiod20)
	{
		vector<int> tezina[21];
		for (int i = 0; i < n; i++)
		{
			for (int j = a[i].first; j <= a[i].second; j++)
			{
				tezina[j].push_back(i + 1);
			}
		}
		for (int i = 0; i < m; i++)
		{
			int x, y, t; cin >> x >> y >> t;
			cout << prvimanji(y, tezina[t]) - prviveci(x, tezina[t]) + 1 << endl;
		}
	}
	else
	{
		sort(begin(a), end(a));
		vector<int>b(a.size() + 1);
		for (int i = 0; i < a.size(); i++)
		{
			b[i] = a[i].first;
		}
		b[a.size()] = a[a.size() - 1].second + 1;
		for (int i = 0; i < m; i++)
		{
			int l, r, t; cin >> l >> r >> t;
			l--; r--;
			int x = prvimanji(t, b);
			if (l <= x && x <= r) cout << 1 << endl;
			else cout << 0 << endl;
		}
	}
}