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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static int m;

    public static void main(String[] args) {
        QuickScanner sc = new QuickScanner();
        int n = sc.nextInt();
        m = sc.nextInt();
//        long ts = System.currentTimeMillis();

        Vertex[][] sortedRows = new Vertex[n][m];
        Vertex[][] sortedColumns = new Vertex[m][n];
        List<List<Integer>> connections = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                int value = sc.nextInt();
                int index = getIndex(i, j);
                sortedRows[i][j] = new Vertex(index, value);
                sortedColumns[j][i] = sortedRows[i][j];
                connections.add(new ArrayList<>());
            }
        }
//        long ts1 = System.currentTimeMillis();

        for (int i = 0; i < n; i++) {
            Arrays.sort(sortedRows[i]);
            createEdgesBetweenEquals(connections, sortedRows[i]);
        }

        for (int j = 0; j < m; j++) {
            Arrays.sort(sortedColumns[j]);
            createEdgesBetweenEquals(connections, sortedColumns[j]);
        }

//        long ts2 = System.currentTimeMillis();

        // merge connected components
        boolean[][] visited = new boolean[n][m];
        int [][] components = new int[n][m];
        int numberOfComponents = 0;
        for (int index = 0; index < connections.size(); index++) {
            int x = getX(index);
            int y = getY(index);
            if (!visited[x][y]) {
                visited[x][y] = true;

                Queue<Integer> queue = new LinkedList<>();
                queue.add(index);
                while (!queue.isEmpty()) {
                    int current = queue.poll();
                    components[getX(current)][getY(current)] = numberOfComponents;
                    for (int next : connections.get(current)) {
                        int nextX = getX(next);
                        int nextY = getY(next);
                        if (!visited[nextX][nextY]) {
                            visited[nextX][nextY] = true;
                            queue.add(next);
                        }
                    }
                }
                numberOfComponents++;
            }
        }

//        long ts3 = System.currentTimeMillis();

        List<List<Integer>> edges = new ArrayList<>();
        for (int i = 0; i < numberOfComponents; i++) {
            edges.add(new ArrayList<>());
        }

        for (int i = 0; i < n; i++) {
            addEdge(components, edges, sortedRows[i]);
        }

        for (int j = 0; j < m; j++) {
            addEdge(components, edges, sortedColumns[j]);
        }

//        long ts4 = System.currentTimeMillis();

        int[] values = new int[numberOfComponents];
        final StringBuilder builder = new StringBuilder(m * n * 2);
        for (int i = 0; i < n; i++) {
            builder.append(getValue(edges, components[i][0], values));
            for (int j = 1; j < m; j++) {
                builder.append(" ").append(getValue(edges, components[i][j], values));
            }
            builder.append("\n");
        }
        System.out.print(builder.toString());
//        long end = System.currentTimeMillis();
//        System.out.println("\nInit: " + (ts1 - ts));
//        System.out.println("Prepare to merge: " + (ts2 - ts1));
//        System.out.println("Merge: " + (ts3 - ts2));
//        System.out.println("Prepare to compress: " + (ts4 - ts3));
//        System.out.println("Compress: " + (end - ts4));
//        System.out.println("Total: " + (end - ts));
    }

    private static int getValue(List<List<Integer>> edges, int index, int[] values) {
        if (values[index] == 0) {
            int max = 0;
            List<Integer> children = edges.get(index);
            for (Integer child : children) {
                max = Math.max(max, getValue(edges, child, values));
            }
            values[index] = max + 1;
        }
        return values[index];
    }

    private static void addEdge(int[][] indexToComponent, List<List<Integer>> edges, Vertex[] vertices) {
        for (int k = vertices.length - 1; k > 0; k--) {
            if (vertices[k].value > vertices[k - 1].value) {
                int from = indexToComponent[getX(vertices[k].index)][getY(vertices[k].index)];
                int to = indexToComponent[getX(vertices[k - 1].index)][getY(vertices[k - 1].index)];
                edges.get(from).add(to);
            }
        }
    }

    private static void createEdgesBetweenEquals(List<List<Integer>> edges, Vertex[] vertexes) {
        for (int k = 0; k < vertexes.length - 1; k++) {
            if (vertexes[k].value == vertexes[k + 1].value) {
                edges.get(vertexes[k].index).add(vertexes[k + 1].index);
                edges.get(vertexes[k + 1].index).add(vertexes[k].index);
            }
        }
    }

    private static int getIndex(int x, int y) {
        return x * m + y;
    }

    private static int getX(int index) {
        return index / m;
    }

    private static int getY(int index) {
        return index % m;
    }

    private static class Vertex implements Comparable<Vertex> {
        private int index;
        private int value;

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

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

        @Override
        public String toString() {
            return "(" + getX(index) + ", " + getY(index) + ") -> " + value;
        }
    }

    private static class QuickScanner {
        BufferedReader in;
        StringTokenizer token;

        public QuickScanner() {
            this.in = new BufferedReader(new InputStreamReader(System.in));
            this.token = new StringTokenizer("", " \n\t");
        }

        public boolean hasNext() {
            while (!token.hasMoreTokens()) {
                try {
                    String s = in.readLine();
                    if (s == null) return false;
                    token = new StringTokenizer(s, " \n\t");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return true;
        }

        public String nextLine() {
            try {
                return in.readLine();
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        public String next() {
            hasNext();
            return token.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}
