#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n, m;
    long long maks = 0, br = 0;
    cin >> n >> m;
    pair<int, int> a[n], b[m];
    for(int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    for(int i = 0; i < m; i++) {
        cin >> b[i].first >> b[i].second;
    }
    if(n == 1){
        int h[m];
        for(int i = 0; i < m; i++) {
            h[i] = b[i].first;
            maks += b[i].first;
            br++;
        }
        for(int i = 0; i < m; i++){
            if(maks + b[i].second - b[i].first <= a[0].second) {
                h[i] = b[i].second;
                maks += b[i].second - b[i].first;
            }
            else {
                h[i] += a[0].second - maks;
                maks = a[0].second;
                break;
            }
        }
        cout << maks <<"\n" << br << "\n";
        for(int i = 0; i < br; i++) {
            cout << 1 << " " << i + 1 << " " << h[i] << "\n";
        }
    }
    return 0;
}