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

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

	int n, m;
	cin>> n >> m;
    int len = n*m, fl = 0, kol = 0;

    int u1[m] = {0}, t1[m] = {0}, t2[n] = {0};
    vector <vector <int> > sf(m);
    vector <vector <int> >  need(n);
    for(int i = 0; i < m; i++)
    {
        sf[i].resize(n);
    }
    for(int i = 0; i < n; i++)
    {
        need[i].resize(m);
    }
    
    for(int i = 0; i < n; i++)
    {
        int a, hesh[m] = {0};
        for(int j = 0; j < m; j++)
        {
            cin >> a;
            a--;
            if(hesh[a])
            {
                sf[a][t1[a]] = i*m + j;
                t1[a]++;
            }
            else hesh[a]++;

        }
        for(int j = 0; j < m; j++)
        {
            // cout << hesh[j] << " "; 
            if(!hesh[j])
            {
                need[i][j]++;
                fl = j;
                kol++;
            }
        }
        // cout << "\n";
    }

    // cout << fl;
    cout << kol + 1 << "\n";
    cout << sf[fl][u1[fl]] + 1 << " " << n*m + 1 << "\n";

    int empty = sf[fl][u1[fl]];
    u1[fl]++;
    for(int i = 1; i < kol; i++)
    {
        int ch, num = empty/m;
        for(int j = 0; j < m; j++)
        {
            if(need[num][j])
            {
                ch = j;
                need[num][j]--;
                break;
            }
        }
        cout << sf[ch][u1[ch]] + 1 << " " << empty + 1 << "\n";
        empty = sf[ch][u1[ch]];
        u1[ch]++;
    }
    cout << n*m + 1 << " " << empty + 1;
}
