#include <bits/stdc++.h>

using namespace std;

long long ma (long long x, long long y) {

    if (x > y) { return x; }
    return y;

}

long long mi (long long x, long long y) {

    if (x < y) { return x; }
    return y;

}

int main () {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    long long n, m;

    cin >> n >> m;


    long long r1[n], r2[n];
    long long k1[m], k2[m];

    for (long long i = 0 ; i < n ; i++) {

        cin >> r1[i] >> r2[i];

    }

    for (long long i = 0 ; i < m ; i++) {

        cin >> k1[i] >> k2[i];

    }

    long long br_num = 0;
    long long br_sum = 0;

    vector<long long> br_num_arr;
    vector<long long> br_num_row;
    vector<long long> br_num_col;

    for (int i = 0 ; i < n ; i++) {

        long long mr = ma(r1[i], r2[i]);

        for (int j = 0 ; j < m ; j++) {

            long long mk = ma(k1[j], k2[j]);

            long long mkol;
            if (j != m-1) { mkol = mi(k1[j+1], k2[j+2]); }
            else { mkol = 0; }

            long long br = mi(mr, mk) - mkol;

            if (br < 1) { continue; }

            br_num++;
            br_sum += br;
            br_num_arr.push_back(br);
            br_num_row.push_back(i+1);
            br_num_col.push_back(j+1);

        }

    }

    cout << br_sum << "\n";
    cout << br_num << "\n";

    for (long long i = 0 ; i < br_num ; i++) {

        cout << br_num_row[i] << " " << br_num_col[i] << " " << br_num_arr[i] << "\n";

    }

    return 0;

}