#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
#include<set>
#include<cassert>
#include<vector>
using namespace std;
const int MAXN = 400 * 1000 + 7;
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];
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);
	if (n > 3000)
	{
		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));
			}
		}
		for (int i = 1; i <= q; i++)
		{
			long long X, Y;
			scanf("%lld %lld", &X, &Y);
			ray bar(1, 1);
			int pp = upper_bound(downPoints.begin(), downPoints.end(), make_pair(X, (int)1e9)) - downPoints.begin();
			int l = -1, r = pp;
			while (r - l > 1)
			{
				int m = (l + r) / 2;
				if (m < 0)
				{
					l = m;
					continue;
				}
				int mm = downPoints[m].second;
				ray go = ray(x[mm] - X, y[mm] - Y);
				if (bad(go, bar))
				{
					l = m;
				}
				else
				{
					r = m;
				}
			}
			printf("%lld ", x[downPoints[r].second - 1]);
			l = pp, r = (int)downPoints.size();
			while (r - l>1)
			{
				int m = (l + r) / 2;
				int mm = downPoints[m].second;
				ray go = ray(X - x[mm], y[mm] - Y);
				if (bad(go, bar))
				{
					r = m;
				}
				else
				{
					l = m;
				}
			}
			int id = downPoints[l].second;
			if (x[id + 1] >= x[id]) id++;
			printf("%lld\n", x[id]);
		}
		return 0;
	}
	x[1] = 0;
	y[1] = 0;
	n++;
	for (int i = 2; i <= n; i++)
	{
		long long d, k;
		scanf("%lld %lld", &d, &k);
		x[i] = x[i - 1] + d;
		y[i] = y[i - 1] + d*k;
	}
	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];
			}
		}
	}
}