include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
define x first
define y second
using namespace std;
typedef pair[HTML_REMOVED] PII;
const int N=300010;
int n,m;
int a[N],s[N];
vector[HTML_REMOVED] adds,query;
vector[HTML_REMOVED] alls;
int find(int x){
int l=0,r=alls.size()-1;
while(l[HTML_REMOVED]>1;
if(alls[mid]>=x) r=mid;
else l=mid+1;
}
return l+1;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i){
int c,x;
cin>>c>>x;
adds.push_back({c,x});
alls.push_back(c);
}
for(int i=1;i<=m;i){
int l,r;
cin>>l>>r;
query.push_back({l,r});
alls.push_back(l);
alls.push_back(r);
}
sort(alls.begin(),alls.end());
alls.erase(unique(alls.begin(),alls.end()),alls.end());
for(int i=0;i<n;i++){
int c=adds[i].x;
int x=adds[i].y;
a[find(c)]+=x;
}
for(int i=1;i<=alls.size();i++) s[i]=s[i-1]+a[i];
for(int i=0;i<m;i++){
int l=find(query[i].x),r=find(query[i].y);
cout<<s[r]-s[l-1]<<endl;
}
return 0;
}