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

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n*m];
    vector<int> nd[n];
    vector<int> dn[m+1];
    map<int, vector<int> > mp[n];
    for(int i = 0; i < n*m; i++){
        cin >> a[i];
        mp[i/m][a[i]].push_back(i);
    }
    int res = 0;
    int c = -1;
    int sp = -1;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= m; j++){
            if(mp[i].find(j) == mp[i].end()){
                nd[i].push_back(j);
                res++;
            }else if(mp[i][j].size() > 1){
                for(int z = 0; z < mp[i][j].size()-1; i++){
                    dn[j].push_back(mp[i][j][z]);
                    sp = mp[i][j][z];
                    c = i;
                }
            }
        }
    }
    if(res == 0){
        cout << 0;
        return 0;
    }
    cout << res+1 << endl;
    cout << sp << ' ' << n*m+1 << endl;

    while(--res){
        cout << dn[nd[c].back()].back() << ' ' << sp << endl;
        sp = dn[nd[c].back()].back();
        c = sp/n;
        dn[nd[c].back()].pop_back();
        nd[c].pop_back();
    }
    cout << n*m+1 << ' ' << sp << endl;

}
