#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
#include<set>
#include<cassert>
#include<vector>
using namespace std;
const int MAXN = 400 * 1000 + 7;
const int MAGIC = 10000;
struct ray
{
	long long x, y;
	ray(long long dx, long long dy)
	{
		x = dx;
		y = dy;
	}
};
bool bad(ray a, ray b)
{
	return a.y*b.x - a.x*b.y > 0;
}
long long x[MAXN], y[MAXN];
long long ans1[MAXN], ans2[MAXN];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	freopen("mountain.in", "r", stdin);
	freopen("mountain.out", "w", stdout);
	int n, q;
	scanf("%d %d", &n, &q);
	vector<pair<long long, long long> >go;
	for (int i = 1; i <= n; i++)
	{
		long long d, k;
		scanf("%lld %lld", &d, &k);
		if (go.empty() || go.back().second != k)
		{
			go.push_back(make_pair(d, k));
		}
		else
		{
			go.back().first += d;
		}
	}
	n = (int)go.size();
	n++;
	vector<pair<long long, int> >downPoints;
	downPoints.push_back(make_pair(0, 0));
	for (int i = 2; i <= n; i++)
	{
		long long d, k;
		d = go[i - 2].first, k = go[i - 2].second;
		x[i] = x[i - 1] + d;
		y[i] = y[i - 1] + d*k;
		if (k == -1)
		{
			downPoints.push_back(make_pair(x[i], i));
		}
	}
	bool group4 = true;
	for (int i = 0; i < (int)go.size(); i++)
	{
		if (go[i].second != -1 && go[i].second != 1) group4 = false;
	}
	if (group4)
	{
		for (int i = 1; i <= q; i++)
		{
			long long X, Y;
			scanf("%lld %lld", &X, &Y);
			if (2 == 2) //goLeft
			{
				int l = 1, r = n + 1;
				while (r - l > 1)
				{
					int m = (l + r) / 2;
					if (x[m] <= X)
					{
						l = m;
					}
					else
					{
						r = m;
					}
				}
				int pos = l;
				l = 0, r = pos;
				while (r - l > 1)
				{
					int m = (l + r) / 2;
					if (y[m] - x[m] <= Y - X)
					{
						r = m;
					}
					else
					{
						l = m;
					}
				}
				if (r > 1 && y[r - 1] > y[r]) r--;
				printf("%lld ", x[r]);
			}
			if (2 == 2) //goRight
			{
				int l = 1, r = n + 1;
				while (r - l > 1)
				{
					int m = (l + r) / 2;
					if (x[m] >= X)
					{
						r = m;
					}
					else
					{
						l = m;
					}
				}
				int pos = r;
				l = pos, r = n + 1;
				while (r - l > 1)
				{
					int m = (l + r) / 2;
					if (y[m] + x[m] <= Y + X)
					{
						l = m;
					}
					else
					{
						r = m;
					}
				}
				if (l < n && y[l + 1] > y[l]) l++;
				printf("%lld\n", x[l]);
			}
		}
		return 0;
	}
	if (n > 3005)
	{
		vector<pair<pair<long long, long long>, int> >qq;
		for (int i = 1; i <= q; i++)
		{
			long long X, Y;
			scanf("%lld %lld", &X, &Y);
			qq.push_back(make_pair(make_pair(X, Y), i));
		}
		sort(qq.begin(), qq.end());
		if (2 == 2) // from left to right, find right corner
		{
			int lpos = n, rpos = 1;
			for (int i = 0; i < (int)qq.size(); i++)
			{
				long long X = qq[i].first.first, Y = qq[i].first.second;
				while (rpos <= n && x[rpos] < X) rpos++;
				int id = qq[i].second;
				ray cur = ray(X - x[lpos], Y - y[lpos]);
				long long lastX = x[lpos];
				while (lpos > 0)
				{
					ray go = ray(X - x[lpos - 1], Y - y[lpos - 1]);
					if (lpos == 1 || bad(go, cur))
					{
						//  ans1[id] = lastX;
						break;
					}
					else
					{
						lpos--;
						cur = go;
						lastX = x[lpos];
					}
				}
				cur = ray(x[rpos] - X, Y - y[rpos]);
				lastX = x[rpos];
				while (rpos <= n + 1)
				{
					ray go = ray(x[rpos + 1] - X, Y - y[rpos + 1]);
					if (rpos == n || bad(go, cur))
					{
						ans2[id] = lastX;
						break;
					}
					else
					{
						cur = go;
						rpos++;
						lastX = x[rpos];
					}
				}
			}
			lpos++;
			rpos = max(1, rpos - MAGIC);
		}
		reverse(qq.begin(), qq.end());
		if (2 == 2) // from right to left, find left corner
		{
			int lpos = n, rpos = 1;
			for (int i = 0; i < (int)qq.size(); i++)
			{
				long long X = qq[i].first.first, Y = qq[i].first.second;
				while (lpos > 0 && x[lpos] > X) lpos--;
				int id = qq[i].second;
				ray cur = ray(X - x[lpos], Y - y[lpos]);
				long long lastX = x[lpos];
				while (lpos > 0)
				{
					ray go = ray(X - x[lpos - 1], Y - y[lpos - 1]);
					if (lpos == 1 || bad(go, cur))
					{
						ans1[id] = lastX;
						break;
					}
					else
					{
						lpos--;
						cur = go;
						lastX = x[lpos];
					}
				}
				cur = ray(x[rpos] - X, Y - y[rpos]);
				lastX = x[rpos];
				while (rpos <= n + 1)
				{
					ray go = ray(x[rpos + 1] - X, Y - y[rpos + 1]);
					if (rpos == n || bad(go, cur))
					{
						//ans2[id] = lastX;
						break;
					}
					else
					{
						cur = go;
						rpos++;
						lastX = x[rpos];
					}
				}
			}
			lpos = min(n, lpos + MAGIC);
			rpos--;
		}
		for (int i = 1; i <= q; i++)
		{
			printf("%lld %lld\n", ans1[i], ans2[i]);
		}
		return 0;
	}
	for (int i = 1; i <= q; i++)
	{
		long long X, Y;
		scanf("%lld %lld", &X, &Y);
		int lpos = 0;
		for (int j = 1; j <= n; j++)
		{
			if (x[j] <= X) lpos = j;
		}
		int rpos = 0;
		for (int j = n; j >= 1; j--)
		{
			if (x[j] >= X) rpos = j;
		}
		ray cur = ray(X - x[lpos], Y - y[lpos]);
		long long lastX = x[lpos];
		for (int j = lpos - 1; j >= 0; j--)
		{
			ray go = ray(X - x[j], Y - y[j]);
			if (j == 0 || bad(go, cur))
			{
				printf("%lld ", lastX);
				break;
			}
			else
			{
				cur = go;
				lastX = x[j];
			}
		}
		cur = ray(x[rpos] - X, Y - y[rpos]);
		lastX = x[rpos];
		for (int j = rpos + 1; j <= n + 1; j++)
		{
			ray go = ray(x[j] - X, Y - y[j]);
			if (j == n + 1 || bad(go, cur))
			{
				printf("%lld\n", lastX);
				break;
			}
			else
			{
				cur = go;
				lastX = x[j];
			}
		}
	}
}