Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and many others. Inspired by the new knowledge, Petya is now developing the new compression algorithm which he wants to name dis.

Petya decided to compress tables. He is given a table a consisting of n rows and m columns that is filled with positive integers. He wants to build the table a' consisting of positive integers such that the relative order of the elements in each row and each column remains the same. That is, if in some row i of the initial table ai, j < ai, k, then in the resulting table a'i, j < a'i, k, and if ai, j = ai, k then a'i, j = a'i, k. Similarly, if in some column j of the initial table ai, j < ap, j then in compressed table a'i, j < a'p, j and if ai, j = ap, j then a'i, j = a'p, j. 

Because large values require more space to store them, the maximum value in a' should be as small as possible.

Petya is good in theory, however, he needs your help to implement the algorithm.

Input

The first line of the input contains two integers n and m (<image>, the number of rows and the number of columns of the table respectively.

Each of the following n rows contain m integers ai, j (1 ≤ ai, j ≤ 109) that are the values in the table.

Output

Output the compressed table in form of n lines each containing m integers.

If there exist several answers such that the maximum number in the compressed table is minimum possible, you are allowed to output any of them.

Examples

Input

2 2
1 2
3 4


Output

1 2
2 3


Input

4 3
20 10 30
50 40 30
50 60 70
90 80 70


Output

2 1 3
5 4 3
5 6 7
9 8 7

Note

In the first sample test, despite the fact a1, 2 ≠ a21, they are not located in the same row or column so they may become equal after the compression.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Comparator;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Artem Gilmudinov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskAcmpFast solver = new TaskAcmpFast();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskAcmpFast {
        boolean[] rowUsed;
        boolean[] colUsed;
        ArrayList<ArrayList<Ceil>> rows;
        ArrayList<ArrayList<Ceil>> cols;
        int[] minRow;
        int[] minCol;
        int[][] bordersRow;
        int[][] bordersCol;
        int[] borders = new int[2];
        int[] valRow;
        ArrayList<Integer> rowPicked;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n, m;
            n = in.readInt();
            m = in.readInt();
            rowUsed = new boolean[n];
            colUsed = new boolean[m];
            Ceil[] ceils = new Ceil[n * m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    ceils[i * m + j] = new Ceil(i, j, in.readInt());
                }
            }
            rows = new ArrayList<>();
            bordersCol = new int[m][2];
            bordersRow = new int[n][2];
            for (int i = 0; i < n; i++) {
                rows.add(new ArrayList<Ceil>());
            }
            cols = new ArrayList<>();
            for (int i = 0; i < m; i++) {
                cols.add(new ArrayList<Ceil>());
            }

            for (Ceil ceil : ceils) {
                rows.get(ceil.x).add(ceil);
                cols.get(ceil.y).add(ceil);
            }
            Comparator<Ceil> cmp = new Comparator<Ceil>() {

                public int compare(Ceil o1, Ceil o2) {
                    return o1.v - o2.v;
                }
            };
            for (ArrayList<Ceil> row : rows) {
                Collections.sort(row, cmp);
            }
            for (ArrayList<Ceil> col : cols) {
                Collections.sort(col, cmp);
            }
            Arrays.sort(ceils, cmp);
            int total = n * m;
            valRow = new int[n];
            rowPicked = new ArrayList<>();
            minRow = new int[n];
            minCol = new int[m];
            int[][] ans = new int[n][m];
            for (int i = 0; i < total; ) {
                int j = i;
                for (; j < total; j++) {
                    if (ceils[i].v != ceils[j].v) {
                        break;
                    }
                }
                for (int z = i; z < j; z++) {
                    Ceil ceil = ceils[z];
                    findBorders(ceil.x, true, ceil.v);
                    //System.out.println("BORDERS " + ceil.v + " " + Arrays.toString(borders) + " " + ceil.x);
                    bordersRow[ceil.x][0] = borders[0];
                    bordersRow[ceil.x][1] = borders[1];
                    findBorders(ceil.y, false, ceil.v);
                    //System.out.println("BORDERS " + ceil.v + " " + Arrays.toString(borders));
                    bordersCol[ceil.y][0] = borders[0];
                    bordersCol[ceil.y][1] = borders[1];
                }
                for (int z = i; z < j; z++) {
                    Ceil ceil = ceils[z];
                    rowPicked.clear();
                    if (!rowUsed[ceil.x]) {
                        // System.out.println("------ " + ceil.v);
                        int res = dfs(ceil.x, true);
                        //System.out.println("WOW " + rowPicked + " " + res + " " + ceil.v);
                        for (int v : rowPicked) {
                            valRow[v] = res;
                        }
                        //  System.out.println(Arrays.toString(valRow));
                    }

                }
                for (int z = i; z < j; z++) {
                    Ceil ceil = ceils[z];
                    ans[ceil.x][ceil.y] = valRow[ceil.x] + 1;
                    minRow[ceil.x] = Math.max(ans[ceil.x][ceil.y], minRow[ceil.x]);
                    minCol[ceil.y] = Math.max(ans[ceil.x][ceil.y], minCol[ceil.y]);
                }
                // System.out.println("MIN " + Arrays.toString(minRow) + " " + Arrays.toString(minCol));
                for (int z = i; z < j; z++) {
                    Ceil ceil = ceils[z];
                    rowUsed[ceil.x] = colUsed[ceil.y] = false;
                }
                i = j;

            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    out.print(ans[i][j] + " ");
                }
                out.println();
            }
        }

        void findBorders(int ind, boolean flag, int val) {
            int left, right, mid;
            ArrayList<Ceil> vector;
            if (flag) {
                vector = rows.get(ind);
            } else {
                vector = cols.get(ind);
            }
            left = 0;
            right = vector.size() - 1;
            while (left < right) {
                mid = left + (right - left) / 2;
                if (vector.get(mid).v < val) {
                    left = mid + 1;
                } else {
                    right = mid;
                }
            }
            //System.out.println("BS " + left + " " + right);
            borders[0] = left;
            left = 0;
            right = vector.size() - 1;
            while (left < right) {
                mid = left + (right - left) / 2;
                if (vector.get(mid).v <= val) {
                    left = mid + 1;
                } else {
                    right = mid;
                }
            }
            if (vector.get(left).v != val) {
                left--;
            }
            borders[1] = left;
        }

        public int dfs(int ind, boolean flag) {
            int res;
            int left, right, x, y;
            if (flag) {

                rowPicked.add(ind);
                res = minRow[ind];
                rowUsed[ind] = true;
                left = bordersRow[ind][0];
                right = bordersRow[ind][1];
                //System.out.println(ind + " " + flag + " " + left + " " + right);
                for (int i = left; i <= right; i++) {
                    y = rows.get(ind).get(i).y;
                    if (!colUsed[y]) {
                        res = Math.max(res, dfs(y, false));
                    }
                }

            } else {
                res = minCol[ind];
                colUsed[ind] = true;
                left = bordersCol[ind][0];
                right = bordersCol[ind][1];
                //System.out.println(ind + " " + flag + " " + left + " " + right);

                for (int i = left; i <= right; i++) {
                    x = cols.get(ind).get(i).x;
                    if (!rowUsed[x]) {
                        res = Math.max(res, dfs(x, true));
                    }
                }
            }
            return res;
        }

        class Ceil {
            int x;
            int y;
            int v;

            public Ceil(int x, int y, int v) {
                this.x = x;
                this.y = y;
                this.v = v;
            }


            public boolean equals(Object obj) {
                Ceil ceil = (Ceil) obj;
                return this.x == ceil.x && this.y == ceil.y;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

