using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A2___Krompiri
{
    internal class Program
    {
        static int OdrediPresek( int a1, int a2, int b1, int b2)
        {
            if (Math.Min(a2, b2) - Math.Max(a1, b1) + 1 > 0)
                return Math.Min(a2, b2) - Math.Max(a1, b1) + 1;
            else
                return 0;
        }
        static void Main(string[] args)
        {
            int ukR = 0;
            int broj = 0;
            int pomocna = 0;
            int ukupno = 0;
            int brpolja = 0;
            string[] s = Console.ReadLine().Split();
            int N = Convert.ToInt32(s[0]);
            int M = Convert.ToInt32(s[1]);
            int[] a = new int[N];
            int[] b = new int[N];
            int[] c = new int[M];
            int[] d = new int[M];
            string[] izlaz = new string[N * M];
            for (int i = 0; i < N; i++)
            {
                s = Console.ReadLine().Split();
                a[i] = Convert.ToInt32(s[0]);
                b[i] = Convert.ToInt32(s[1]);
            }
            for (int i = 0; i < M; i++)
            {
                s = Console.ReadLine().Split();
                c[i] = Convert.ToInt32(s[0]);
                d[i] = Convert.ToInt32(s[1]);
            }
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < M; j++)
                {
                    broj = OdrediPresek(a[i], b[i], c[j], d[j]);
                    if (broj > 0 && ukR < b[i])
                    {
                        ukR += broj;
                        ukupno += broj;
                        brpolja++;
                        izlaz[pomocna] = (i + 1) + " " + (j + 1) + " " + broj;
                        pomocna++;
                    }
                }
                ukR = 0;
            }
            Array.Resize(ref izlaz, pomocna);
            Console.WriteLine(ukupno);
            Console.WriteLine(brpolja);
            foreach (string el in izlaz)
            {
                Console.WriteLine(el);
            }
        }
    }
}