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.*;
import java.util.*;

public class SolutionCF650C implements Runnable {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void solve() throws IOException {
        int t = 1;
        while (t-- > 0) {
            solveTest();
        }
    }

    class Element implements Comparable<Element> {
        int x;
        int index;

        public Element(int x, int index) {
            this.x = x;
            this.index = index;
        }

        @Override
        public int compareTo(Element o) {
            int res = Integer.compare(this.x, o.x);
            if (res != 0) return res;
            return -Integer.compare(this.index, o.index);
        }
    }

    int[][] vert;
    int[][] hor;
    int[][] nextVert;
    int[][] nextHor;
    int[][] a;
    int[][] d;
    boolean[][] used;




    void dfs(int r, int c) {
        if(used[r][c]) return;
        used[r][c] = true;
        d[r][c] = -1;
        int v = 1;
        int h = 1;
        int prevR = vert[r][c];
        if(prevR != -1) {
            dfs(prevR, c);
            if(a[prevR][c] == a[r][c]) {
                v = d[prevR][c];
            } else {
                v = d[prevR][c] + 1;
            }
        }

        int prevC= hor[r][c];
        if(prevC != -1) {
            dfs(r, prevC);
            if(a[r][prevC] == a[r][c]) {
                h = d[r][prevC];
            } else {
                h = d[r][prevC] + 1;
            }
        }
        if(h < v) {
            d[r][c] = v;
        } else {
            d[r][c] = h;
        }
    }
    boolean[][] ue;
    int m;
    void dfsEqual(int r, int c) {
        if(ue[r][c]) return;
        ue[r][c] = true;
        os[size++] = (r * m + c);

        int nextR = vert[r][c];
        if(nextR != -1) {
            if(a[nextR][c] == a[r][c]) {
                dfsEqual(nextR, c);
            }
        }

        int nextC= hor[r][c];
        if(nextC != -1) {
            if(a[r][nextC] == a[r][c]) {
                dfsEqual(r, nextC);
            }
        }
        nextR = nextVert[r][c];
        if(nextR != -1) {
            if(a[nextR][c] == a[r][c]) {
                dfsEqual(nextR, c);
            }
        }

        nextC= nextHor[r][c];
        if(nextC != -1) {
            if(a[r][nextC] == a[r][c]) {
                dfsEqual(r, nextC);
            }
        }

    }


    class El implements Comparable<El> {
        int value;
        int index;

        public El(int value, int index) {
            this.value = value;
            this.index = index;
        }

        @Override
        public int compareTo(El o) {
            return Integer.compare(this.value, o.value);
        }
    }

    int[] os = new int[1000 * 1000 + 10];
    int size = 0;
    int[] first, second;
    void solveTest() throws IOException {
        int n = readInt();
        m = readInt();
        ue = new boolean[n][m];
        El[] els = new El[n * m];
        a = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i][j] = readInt();
                els[i * m + j] = new El(a[i][j], i * m + j);
            }
        }
        vert = new int[n][m];
        hor = new int[n][m];
        nextHor = new int[n][m];
        nextVert = new int[n][m];

        Element[] row = new Element[m];
        for (int i = 0; i < m; i++) {
            row[i] = new Element(0, 0);
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                row[j].x = a[i][j];
                row[j].index = j;
            }
            Arrays.sort(row);
            hor[i][row[0].index] = -1;
            for(int j = 1; j < m; j++) {
                nextHor[i][row[j-1].index] = row[j].index;
                hor[i][row[j].index] = row[j-1].index;
            }
            nextHor[i][row[m-1].index] = -1;

        }
        Element[] column = new Element[n];
        for (int i = 0; i < n; i++) {
            column[i] = new Element(0, 0);
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                column[j].x = a[j][i];
                column[j].index = j;
            }
            Arrays.sort(column);
            vert[column[0].index][i] = -1;
            for(int j = 1; j < n; j++) {
                nextVert[column[j-1].index][i] = column[j].index;
                vert[column[j].index][i] = column[j-1].index;
            }
            nextVert[column[n-1].index][i] = -1;
        }

        used = new boolean[n][m];
        d = new int[n][m];
        first = new int[n*m];
        second = new int[n*m];
        for(int i = 0; i < n * m; i++) {
            first[i] = i / m;
            second[i] = i % m;
        }

        Arrays.sort(els);

        List<List<Integer>> nums = new ArrayList<>();
        List<Integer> cur = new ArrayList<>(1);
        cur.add(els[0].index);

        for(int i = 1; i < n*m; i++) {
            if(els[i].value == els[i-1].value) {
                cur.add(els[i].index);
            } else {
                nums.add(cur);
                cur = new ArrayList<>(1);
                cur.add(els[i].index);
            }
        }
        nums.add(cur);

        for(List<Integer> list: nums) {
            for(int indexes: list) {
                int i = first[indexes];
                int j = second[indexes];
                dfs(i, j);
            }

            for(int indexes: list){
                int i = first[indexes];
                int j = second[indexes];
                if(ue[i][j]) continue;
                size = 0;
                dfsEqual(i, j);
                int max = 0;
                for(int l = 0; l < size; l++){
                    int o = os[l];
                    int i1 = first[o];
                    int j1 = second[o];
                    if(d[i1][j1] > max) {
                        max = d[i1][j1];
                    }
                }

                for(int l = 0; l < size; l++) {
                    int o = os[l];
                    int i1 = first[o];
                    int j1 = second[o];
                    d[i1][j1] = max;
                }
            }
        }
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                out.print(d[i][j] + " ");
            }
            out.println();
        }
    }

    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int[] readArr(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long[] readArrL(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = readLong();
        }
        return res;
    }

    public static void main(String[] args) {
        new Thread(null, new SolutionCF650C(), "", 1l << 26).start();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }
}