#include <bits/stdc++.h>
using namespace std;

int k[405][405];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	int n, m;
	cin>>n>>m;
    int a[n+1][m+1];
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            cin>>a[i][j];
            k[i][a[i][j]]++;
        }
    }
    vector<pair<int,int>> res;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if(k[i][j] > 1)
            {
                for(int i1 = i + 1; i1 <= n; i1++)
                {
                    if(k[i1][j] > 1)
                    {
                        int x;
                        for(int j1 = i + 1; j1 <= n; j1++)
                        {
                            if(a[i][j1] == j)
                            {
                                x = j1;
                            }
                        }
                        for(int j1 = i + 1; j1 <= n; j1++)
                        {
                            if(a[i1][j1] == j)
                            {
                                res.push_back({x*i, n*m+1});
                                res.push_back({i1*j1, x*1});
                                res.push_back({n*m+1, i1*j1});
                                k[i1][j]--;
                                break;
                            }
                            //k[i1][j]--;
                        }
                        if(k[i1][j] == 1)
                        {
                            break;
                        }

                    }
                }
            }
        }
    }
    cout<<res.size()<<'\n';
    for(auto to: res)
    {
        cout<<to.first<<" "<<to.second<<'\n';
    }
}
