#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
int n,m;
vector<int> alls;
vector<PII> add, query; // 存储题目输入的数据
int a[300010] = {0}; // 存储离散化后的数组
int sumMap[300010] = {0}; // 存储离散化后的数组的前缀和
int reflect(int x)
{
int L = 0,R = alls.size()-1; // R不是n-1,因为alls的大小最多能达到300000,而非n
int mid = L + R >> 1;
while(L < R) // 这里必须是<,如果是≤则死循环
{
if(alls[mid] >= x) R = mid;
else L = mid + 1;
mid = L + R >> 1;
}
return R+1; //+1使得数组下标从1开始
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin>>n>>m;
int x,c;
for(int i=0;i<n;++i)
{
cin>>x>>c;
alls.push_back(x);
add.push_back({x,c});
}
int l, r;
for(int i=0;i<m;++i)
{
cin>>l>>r;
query.push_back({l, r});
alls.push_back(l); // 将区间的首尾加入到alls中,方便之后二分查找计算前缀和
alls.push_back(r);
}
// 要保证每个x有且仅有一个对应的映射值,因此需要消去重复的x,下面是公式
sort(alls.begin(), alls.end());
alls.erase(unique(alls.begin(), alls.end()), alls.end());
for(auto it : add)
{
int x = reflect(it.first);
a[x] += it.second;
}
for(int i=1;i<=alls.size();++i) // <=alls.size()而非<=n,原因同reflect()函数里的R
sumMap[i] += sumMap[i-1] + a[i];
for(auto it : query)
{
int l = reflect(it.first);
int r = reflect(it.second);
cout<<sumMap[r] - sumMap[l-1]<<'\n';
}
return 0;
}