#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;

int main()
{
	int n,m;
	cin>>n>>m; 
	vector<int> a(n*m);
	for (int i=0;i<n*m;i++){
		cin>>a[i];
	}
	vector<pair<int,int>> b;
	vector<pair<int,int>> d;
	for (int i=0;i<n;i++){
		vector<bool> c(m+1);
		for (int j=0;j<m;j++){
			if (c[a[m*i+j]]){
				b.push_back(make_pair(m*i+j+1,a[m*i+j]));
			}
			else c[a[m*i+j]]=1;
		}
		for (int j=1;j<m+1;j++){
			if (!c[j]) d.push_back(make_pair(i+1,j));
		}
	}
/*	for(int i=0;i<b.size();i++){
		cout<<b[i].first<<" "<<b[i].second<<endl;
	}
	for(int i=0;i<d.size();i++){
		cout<<d[i].first<<" "<<d[i].second<<endl;
	}*/
	if (b.size()!=0) {
		cout<<b.size()+1<<endl;
		cout<<b[0].first<<" "<<n*m+1<<endl;
		int i=0;
		for (int oper=0;oper<b.size()-1;oper++){
			for (int j=0;j<b.size();j++){
				if (b[j].second==d[i].second){
					cout<<b[j].first<<" "<<b[i].first<<endl;
					i=j;
					break;
				}
			}
		}
		cout<<n*m+1<<" "<<b[i].first<<endl;
	}
	else cout<<0;
}
/*
5 6
2 4 6 4 1 5 
2 4 5 1 3 5 
1 6 1 2 3 6
3 6 5 5 1 2
4 3 4 2 3 6
*/
/*
4 4
12 5
15 1
18 6
22 5
27 4
29 3

1 3
2 6
3 4
3 5
4 4
5 1
5 5
*/
/*
8
4 31
29 4
18 12
4 15
12 18
4 22
15 27
12 29

*/