#include <bits/stdc++.h>
using namespace std;
long long n,m,a[50005],b[50005],c[50005],d[50005],res[50005],res1,br;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
	cin>>a[i]>>b[i];
}
for(int i=1;i<=m;i++){
	cin>>c[i]>>d[i];
	res[i]=c[i];
	if(res[i]>0)res1++;
	br+=c[i];
}
if(br<a[1]){
	while(br<a[1]){
		for(int i=1;i<=m;i++){
			if(res[i]<d[i] and res[i]<c[i]){
				res[i]++;
				br++;
				if(br==a[i])break;
			}
		}
	}
}
cout<<br<<endl;
cout<<res1<<endl;
for(int i=1;i<=m;i++){
	cout<<res[i]<<" ";
}
cout<<endl;






return 0;
}