#include <iostream>
#include <bits/stdc++.h>

#define int long long
#define endl '\n'
#define inf 2000000000000000000
#define random (rand()^(rand()<<15))

using namespace std;
constexpr int mod=1000000007;
constexpr int MOD=998244353;
mt19937 rnd(time(nullptr));

void solve()
{
    int n,m;
    cin>>n>>m;
    int a[n][m];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
    int q=-1;
    vector<pair<int,int>>v;
    for(int i=0;i<n;i++)
    {
        set<int>st;
        for(int j=0;j<n;j++)
        {
            if(st.count(a[i][j]))
            {
                v.push_back({i+1,j+1});
            }
            st.insert(a[i][j]);
        }
    }
    cout<<v.size()+1<<endl;
    cout<<(v[0].first-1)*m+v[0].second<<" "<<(n*m)+1<<endl;
    for(int i=1;i<v.size();i++)
    {
        cout<<(v[i].first-1)*m+v[i].second<<" "<<(v[i-1].first-1)*m+v[i-1].second<<endl;
    }
    cout<<31<<" "<<(v[v.size()-1].first-1)*m+v[v.size()-1].second<<endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t=1;
//    cin>>t;
    for(int _=1;_<=t;_++)
    {
        solve();
    }
}
