#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]=d[i];
        if (c[i]>0) br++;
        sum+=d[i];
    }
    int raz=0;
    if (sum>b){
        raz=sum-b;
        for (int i=1;i<=m;i++){
            if (raz>=c[i] and raz<=d[i]){
                res[i]-=raz;
                sum-=raz;
            }
            if (sum<=b) break;
        }
    }
    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;
}