#include "bits/stdc++.h"
using namespace std;
const int MAX = 111;
int A[MAX][MAX];
int main()
{
int n, m;
scanf("%d%d", &n, &m);
int sum = 0;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
scanf("%d", &A[i][j]);
sum += A[i][j];
}
}
printf("%d\n", sum);
for (int i = n-1; i >= 0; --i)
{
for (int j = m-1; j >= 0; --j)
{
for (int k = A[i][j] - 1; k >= 0; --k)
{
printf("%d %d %d\n", i+1, j+1, k+1);
}
}
}
}