#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);

    int a[n],b[n];
    for (int i=0;i<n;i++)
        scanf("%d %d",&a[i],&b[i]);

    int c[m],d[m];
    for (int i=0;i<m;i++)
        scanf("%d %d",&c[i],&d[i]);

    int suma=0,brojac=0;

    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        {
            int n;
            if (d[j]>=a[i] &&  c[j]<=b[i])
                {
                    n=min(b[i],d[j]);
                    suma=suma+n;
                    brojac++;
                }
        }
    }
    printf("%d\n",suma);
    printf("%d\n",brojac);

    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        {
            if (d[j]>=a[i] &&  c[j]<=b[i])
                {
                    n=min(b[i],d[j]);
                    printf("%d %d %d\n",i+1,j+1,n);
                }
        }
    }

}