#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int> d(n), u(n), l(m), r(m), x(m), ans(m, 0);
	for (int i = 0; i < n; i++)
		cin >> d[i] >> u[i];
	for (int i = 0; i < m; i++)
		cin >> l[i] >> r[i] >> x[i],
		l[i]--, r[i]--;
	bool subtask2 = true;
	bool subtask4 = true;
	for (int i = 0; i < n; i++)
	{
		if (d[i] != u[i])
			subtask2 = false;
		if (u[i] > 20)
			subtask4 = false;
	}
	if (n <= 1000 && m <= 1000)
	{
		for (int i = 0; i < m; i++)
			for (int j = l[i]; j <= r[i]; j++)
				if (x[i] >= d[j] && x[i] <= u[j])
					ans[i]++;
	}
	else if (subtask2)
	{
		vector<pair<int, int>> p(n);
		for (int i = 0; i < n; i++)
			p[i] = { d[i],i };
		sort(p.begin(), p.end());
		for (int i = 0; i < m; i++)
			ans[i] = upper_bound(p.begin(), p.end(), make_pair(x[i], r[i])) - lower_bound(p.begin(), p.end(), make_pair(x[i], l[i]));
	}
	else if (subtask4)
	{
		vector<int> ind[21];
		for (int i = 0; i < n; i++)
			for (int j = d[i]; j <= u[i]; j++)
				ind[j].push_back(i);
		for (int i = 0; i < m; i++)
			ans[i] = upper_bound(ind[x[i]].begin(), ind[x[i]].end(), r[i]) - lower_bound(ind[x[i]].begin(), ind[x[i]].end(), l[i]);
	}
	else
	{
		vector<pair<int, int>> p(n);
		vector<pair<int, int>> v;
		for (int i = 0; i < n; i++)
			p[i] = make_pair(d[i], u[i]);
		sort(p.begin(), p.end());
		int poc = p[0].first;
		int kr = p[0].second;
		for (int i = 1; i < n; i++)
		{
			if (p[i].first > kr)
			{
				v.push_back(make_pair(poc, kr));
				poc = p[i].first;
				kr = p[i].second;
			}
			kr = max(kr, p[i].second);
		}
		v.push_back(make_pair(poc, kr));
		for (int i = 0; i < m; i++)
		{
			int it = upper_bound(v.begin(),v.end(),make_pair(x[i],-1))-v.begin();
			if (it != 0 && v[it - 1].second >= x[i])
				ans[i] = 1;
		}
	}
	for (int i = 0; i < m; i++)
		cout << ans[i] << endl;
}