#include <bits/stdc++.h>
#define pii pair <int, int>
using namespace std;


vector <int> boxes;


int findInGroup (vector <int> v, int n) {
    int res = -1;

    for (int i = 0; i < v.size(); i++) {
        if (boxes[v[i]] == n) {
            res = i;
            break;
        }
    }

    return res;
}


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

	int n, m;
	cin >> n >> m;
    boxes.resize(n*m + 1);
    vector < vector < vector <int> > > groups (n, vector < vector <int> > (2)); // in group: 0 - have more than needed (indexes), 1 - need

    for (int i = 1; i <= n*m; i++) {
        cin >> boxes[i];
    }

    int toFix = 0;

    for (int i = 0; i < n; i++) {
        int a[m+1] = {};

        for (int j = i*m + 1; j <= i*m + m; j++) {
            a[boxes[j]]++;
            if (a[boxes[j]] > 1) groups[i][0].push_back(j);
        }

        for (int j = 1; j < m+1; j++) {
            if (a[j] == 0) {
                groups[i][1].push_back(j);
                toFix++;
            }
        }
    }

    int moveHereI, toFind; // index in 'boxes', number

    for (int i = 0; i < n; i++) {
        if (groups[i][0].size() > 0) {
            moveHereI = groups[i][0][0];
            groups[i][0].erase(groups[i][0].begin());

            toFind = groups[i][1][0];
            groups[i][1].erase(groups[i][1].begin());

            cout << moveHereI << " " << n*m + 1 << "\n";

            break;
        }
    }

    for (int ii = 0; ii < toFix - 1; ii++) {
        for (int i = 0; i < n; i++) { // search through groups
            if (groups[i][0].size() > 0) {
                int fi = findInGroup(groups[i][0], toFind); 
                if (fi != -1) {
                    cout << groups[i][0][fi] << " " << moveHereI << "\n";

                    moveHereI = groups[i][0][fi];
                    groups[i][0].erase(groups[i][0].begin() + fi);

                    toFind = groups[i][1][0];
                    groups[i][1].erase(groups[i][1].begin());

                    break;
                }
            }
        }
    }

    cout << n*m + 1 << " " << moveHereI << endl;
}
