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.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Random;
import java.util.StringTokenizer;

public class ETableCompression {
    public static void main(String[] args) {
        QuickScanner sc = new QuickScanner();
        final int n = sc.nextInt(); //rows
        final int m = sc.nextInt(); //columns
        int[][] table = new int[n][m];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                table[i][j] = sc.nextInt();
            }
        }

        print(solve(n, m, table));
//        test();
    }

    public static void test() {
        final Random random = new Random();
        int n = 1;
        int m = 100;//744740;


        int counter = 0;
        while (true) {
            m += 100;
            if (counter == 1000) {
                m = 744740;
            }
            System.out.println("Count and m " + counter + "\t" + m);
            int[][] input = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    input[i][j] = random.nextInt(1000000000);
                }
            }

            long t1 = System.currentTimeMillis();
            final int[][] myResult = solve(n, m, input);
            System.out.printf("My time: %d\n", (System.currentTimeMillis() - t1));
            t1 = System.currentTimeMillis();
            final int[][] rightResult = new int[n][m];//EWorkingExample.solve(n, m, input);
            System.out.printf("Right time: %d\n", (System.currentTimeMillis() - t1));
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (myResult[i][j] != rightResult[i][j]) {
                        print(input);
                        print(myResult);
                        print(rightResult);
                        System.out.println("ERROR");
                        solve(n, m, input);
                    }
                }
            }
            System.out.printf("Try number #%d\n", ++counter);
            if (counter == Integer.MAX_VALUE) {
                break;
            }
        }
    }

    private static void print(int[][] result) {
        StringBuilder builder = new StringBuilder(result.length * result[0].length * 2);
        for (int i = 0; i < result.length; i++) {
            for (int j = 0; j < result[0].length; j++) {
                builder.append(result[i][j]);
                builder.append(" ");
            }
            builder.append("\n");
        }
        builder.append("\n");
        System.out.println(builder.toString());
    }

    private static boolean SINGLE_ROW_OR_COLUMN = false;

    public static int[][] solve(final int N, final int M, final int[][] input) {
        final int n = N; //rows
        final int m = M; //columns
        Point[][] table = new Point[n][m];

        SINGLE_ROW_OR_COLUMN = (n == 1) || (m == 1);

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                table[i][j] = new Point(i, j, input[i][j]);
            }
        }

        for (int i = 0; i < n; i++) {
            final Point[] row = Arrays.copyOf(table[i], m);
            Arrays.sort(row, (o1, o2) -> Integer.compare(o1.data, o2.data));
            for (int j = 0; j < m - 1; j++) {
                if (row[j].data == row[j + 1].data) {
                    row[j].addEqual(row[j + 1]);
                    row[j + 1].addEqual(row[j]);
                } else {
                    row[j].addNext(row[j + 1]);
                    row[j + 1].addPrev(row[j]);
                }
            }
        }

        for (int i = 0; i < m; i++) {
            final Point[] column = new Point[n];
            for (int j = 0; j < n; j++) {
                column[j] = table[j][i];
            }
            Arrays.sort(column, (o1, o2) -> Integer.compare(o1.data, o2.data));
            for (int j = 0; j < n - 1; j++) {
                if (column[j].data == column[j + 1].data) {
                    column[j].addEqual(column[j + 1]);
                    column[j + 1].addEqual(column[j]);
                } else {
                    column[j].addNext(column[j + 1]);
                    column[j + 1].addPrev(column[j]);
                }
            }
        }

        boolean visited[][] = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                Point point = table[i][j];
                if (visited[i][j] || point.noEquals()) {
                    continue;
                }

                Queue<Point> queue = new LinkedList<>();
                queue.add(point);
                while (!queue.isEmpty()) {
                    Point check = queue.poll();

                    if (visited[check.x][check.y]) {
                        continue;
                    }

                    visited[check.x][check.y] = true;
                    check.componentHolder = point;
                    point.merge(check);
                    check.fillCollectionWithEquals(queue);
                }
                point.componentHolder = null;
            }
        }

        visited = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                Point point = table[i][j];
                if (visited[i][j] || point.componentHolder != null) {
                    continue;
                }

                dp(point, visited);
            }
        }

        int[][] result = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                result[i][j] = table[i][j].componentHolder == null ? table[i][j].data :
                        table[i][j].componentHolder.data;
            }
        }
        /*StringBuilder builder = new StringBuilder(n * m * 2);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                builder.append(table[i][j].componentHolder == null ? table[i][j].data :
                        table[i][j].componentHolder.data);
                builder.append(" ");
            }
            builder.append("\n");
        }
        System.out.println(builder.toString());*/

        return result;
    }

    private static int dp(Point point, boolean[][] visited) {
        if (visited[point.x][point.y]) {
            return point.data;
        }

        if (!point.hasPrev()) {
            visited[point.x][point.y] = true;
            point.data = 1;
            return point.data;
        }

        int max = 0;
        for (Point parent : point.getPrev()) {
            max = Math.max(max, dp(parent.componentHolder == null ? parent : parent.componentHolder, visited));
        }
        visited[point.x][point.y] = true;
        point.data = max + 1;

        return point.data;
    }

    private static class Point {
        public final int x;
        public final int y;
        public int data;
        private Point singleNext = null;
        private List<Point> next = null;
        private Point singlePrev = null;
        private Collection<Point> prev = null;
        private int equalsCount = 0;
        private Point[] equals = new Point[4];
        public Point componentHolder = null;

        public void addEqual(Point point) {
            equals[equalsCount++] = point;
        }

        public boolean noEquals() {
            return equalsCount == 0;
        }

        public void fillCollectionWithEquals(Collection<Point> collection) {
            for (int i = 0; i < equalsCount; i++) {
                collection.add(equals[i]);
            }
        }

        public void addNext(Point point) {
            if (this.equals(point)) {
                return;
            }

            if (SINGLE_ROW_OR_COLUMN && next == null && singleNext == null) {
                singleNext = point;
                return;
            }

            if (next == null) {
                next = new ArrayList<>(2);
                if (singleNext != null) {
                    next.add(singleNext);
                    singleNext = null;
                }
            }
            next.add(point);
        }

        public void addPrev(Point point) {
            if (this.equals(point)) {
                return;
            }

            if (SINGLE_ROW_OR_COLUMN && prev == null && singlePrev == null) {
                singlePrev = point;
                return;
            }

            if (prev == null) {
                prev = new ArrayList<>(2);
                if (singlePrev != null) {
                    prev.add(singlePrev);
                    singlePrev = null;
                }
            }
            prev.add(point);
        }

        public boolean hasPrev() {
            return singlePrev != null || (prev != null && !prev.isEmpty());
        }

        public Collection<Point> getPrev() {
            if (singlePrev != null) {
                return Collections.singletonList(singlePrev);
            }
            return prev != null ? prev : Collections.emptyList();
        }

        public List<Point> getNext() {
            return next != null ? next : Collections.emptyList();
        }

        public Point(final int x, final int y, final int data) {
            this.x = x;
            this.y = y;
            this.data = data;
        }

        @Override
        public boolean equals(final Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }

            final Point point = (Point) o;

            if (x != point.x) {
                return false;
            }
            return y == point.y;

        }

        @Override
        public int hashCode() {
            int result = x;
            result = 1000000 * result + y;
            return result;
        }

        public void merge(Point toMerge) {
            if (this.equals(toMerge)) {
                return;
            }

            for (Point point : toMerge.getPrev()) {
                addPrev(point);
            }
        }
    }

    private static class QuickScanner {
        BufferedReader myIn;
        StringTokenizer myToken;

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

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

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

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

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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }
    }
}