#include <bits/stdc++.h>

#define ll long long

using namespace std;

void print_sol(ll a[], ll sum, int n) {

    cout << sum << endl;
    int br = 0;
    for(int i = 0; i < n; i++)
        if(a[i] != 0)
            br++;
    cout << br << endl;
    for(int i = 0; i < n; i++)
        if(a[i] != 0)
            cout << 1 << " " << i + 1 << " " << a[i] << endl;
}

void test1(pair<ll, ll> a, pair<ll, ll> col[], int n) {

    ll ans[n], sum = 0;
    for(int i = 0; i < n; i++)
        ans[i] = col[i].second, sum += col[i].second;

    if(sum <= a.second) {
        print_sol(ans, sum, n);
        return;
    }

    for(int i = 0; i < n; i++) {
        ll diff = col[i].second - col[i].first;
        if(sum - diff > a.second) {
            sum -= diff;
            ans[i] -= diff;
            continue;
        }

        ans[i] -= sum - a.second;
        sum = a.second;
        print_sol(ans, sum, n);
        break;
    }
}

int main() {

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

    int n, m;
    cin >> n >> m;

    pair<ll, ll> row[n], col[m];
    for(int i = 0; i < n; i++)
        cin >> row[i].first >> row[i].second;
    for(int i = 0; i < m; i++)
        cin >> col[i].first >> col[i].second;

    if(n == 1) {
        test1(row[0], col, m);
        return 0;
    }
    return 0;
}