#include <bits/stdc++.h>
using namespace std;

int n, m;
long long ogrRed[50005][2]; //u zadatku, a i b
long long ogrKol[50005][3]; //u zadatku, c i d

//RESENJE ZA n=1

long long brPolja;
long long brKrompira;

long long polje[10][50005];

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%lld %lld", &ogrRed[i][0], &ogrRed[i][1]);
	}
	for (int i = 1; i <= m; ++i)
	{
		scanf("%lld %lld", &ogrKol[i][0], &ogrKol[i][1]);
	}

	if (ogrRed[1][1] != 0)
	{
		for (int i = 1; i <= m; ++i)
		{
            polje[1][i] = ogrKol[i][1];

            if (brKrompira+polje[1][i] > ogrRed[1][1])
			{
				polje[1][i] = ogrRed[1][1] - brKrompira;
				if (polje[1][i] < ogrKol[i][0])
				{
					polje[1][i] = 0;
					continue;
				}
			}

            if (polje[1][i] > 0)
			{
				++brPolja;
				brKrompira+=polje[1][i];
			}
		}
	}


	printf("%lld\n", brKrompira);
	printf("%lld\n", brPolja);
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= m; ++j)
		{
			if (polje[i][j] > 0)
			{
				printf("%d %d %lld\n", i, j, polje[i][j]);
			}
		}
	}



	return 0;
}