#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define LPRINT(a, b) for (auto&(a) : (b))
#define li(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define lij(i,a,b) for (int (i) = (a); (i) <= (b); (i)++)

int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, m;
cin>>n>>m;
vector<int> a(n), b(n), c(m), d(m);
li(i,0,n){
	cin>>c[i]>>d[i];
}
li(i,0,m){
	cin>>a[i]>>b[i];
}
vector<int> p(m);
ll zbir = 0;
li(i,0,m){
	p[i] = a[i];
	zbir+=a[i];
}
d[0]-=zbir;
li(i,0,m){
	if(d[0]==0){
		break;
	}
	int temp = min(d[0],b[i]-p[i]);
	p[i]+= temp;
	d[0]-=temp;
	zbir+=temp;
}
//ispis
cout<<zbir<<endl;
int y = 0;
li(i,0,m){
	if(p[i]!=0) y++;
}
cout<<y<<endl;
li(i,0,m){
	if(p[i]==0) continue;
	cout<<1<<" "<<i+1<<" "<<p[i]<<endl;
}
return 0;
}