#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int n,m;
void set1(){
    int a,b,res[50005],c[50005],d[50005],br=0,sum=0;
    cin >> a >> b;
    for (int i=1;i<=m;i++){
        cin >> c[i] >> d[i];
        res[i]=c[i];
        if (c[i]>0) br++;
        sum+=c[i];
    }
    if (sum<a){
        for (int i=1;i<=m;i++){
            res[i]=d[i];
            sum+=d[i]-c[i];
            if (sum>a and sum<b) break;
            if (sum>b){
                sum-=sum-b;
                res[i]-=res[i]-sum+b;
            }
        }
    }
    cout << sum << "\n" << br << "\n";
    for (int i=1;i<=m;i++){
        if (res[i]>0) cout << "1 " << i << " " << res[i] << "\n";
    }
};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    if (n==1) set1();
    else {

        cout << "1\n1\n1 1 1";

    }
    return 0;
}