#include <bits/stdc++.h>
#define en '\n'
#define ll long long
#define sp ' '

using namespace std;

int main()
{
    ll N, M;
    cin >> N >> M;
    vector <ll> a (N + 1, 0);
    vector <ll> b (N + 1, 0);
    vector <ll> c (N + 1, 0);
    vector <ll> d (N + 1, 0);
    ll sa = 0;
    ll sb = 0;
    ll sc = 0;
    ll sd = 0;
    for (ll i = 1; i <= N; i++)
    {
        cin >> a[i] >> b[i];
        sa += a[i], sb += b[i];
    }
    for (ll j = 1; j <= M; j++)
    {
        cin >> c[j] >> d[j];
        sc += c[j], sd += d[j];
    }
    cout << sb << en;
    cout << N << en;
    for (ll i = 1; i <= N; i++)
        cout << i << sp << i << sp << b[i] << en;
}