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

public class Main {
    public static void main(String[] args) {
//     Test.testing();
        ConsoleIO io = new ConsoleIO();
        new Main(io).solve();
        io.flush();
    }

    ConsoleIO io;

    Main(ConsoleIO io) {
        this.io = io;
    }

    ArrayList<ArrayList<Integer>> gr1;
    boolean[] visit;
    //

    class Pair {
        public Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        public int a;
        public int b;
    }

    class Edge {
        public Edge(int c, int u, int v) {
            this.u = u;
            this.v = v;
            this.c = c;
        }

        public int u;
        public int v;
        public int c;
    }

    class Bucket{
        public Bucket(int i, int j){
            allx = new HashSet<>();
            ally = new HashSet<>();
            points= new ArrayList<>();
            allx.add(i);
            ally.add(j);
            points.add(new Pair(i,j));
        }

        public HashSet<Integer> allx;
        public HashSet<Integer> ally;
        public List<Pair> points;
        public Bucket next;
    }

    long MOD = 1_000_000_007;
    int n, m, k;
    int[][] map;
    int move, change, time;

    public void solve() {
        int[] l = io.readIntArray();
        n = l[0];
        m = l[1];
        int[] map = new int[n*m];
        ArrayList<Integer> nums = new ArrayList<>();
        HashMap<Integer, List<Pair>> points = new HashMap<>();

        for (int i = 0; i < n; i++) {
            int[] ar = io.readIntArray();
            for (int j = 0; j < m; j++) {
                int t = ar[j];
                if (points.containsKey(t)) {
                    points.get(t).add(new Pair(i, j));
                } else {
                    ArrayList<Pair> list = new ArrayList<>(1);
                    list.add(new Pair(i, j));
                    points.put(t, list);
                    nums.add(t);
                }
            }
        }

        int[] maxV = new int[n];
        int[] maxH = new int[m];

        nums.sort(Comparator.naturalOrder());

        tree = new int[n+m];
        height = new int[n+m];
        for(int i = 0 ;i<tree.length;i++)tree[i] = i;

        for (int i = 0; i < nums.size(); i++) {
            List<Pair> ppp = points.get(nums.get(i));

            for(Pair p : ppp){
                int a = p.a, b = p.b+n;
                int ga = get(a), gb = get(b);
                if(ga!=gb) {
                    if (height[ga] < height[gb]) {
                        tree[ga] = gb;
                        height[gb] = Math.max(height[gb], height[ga] + 1);
                    } else {
                        tree[gb] = ga;
                        height[ga] = Math.max(height[ga], height[gb] + 1);
                    }
                }
            }

            HashMap<Integer, List<Pair>> group = new HashMap<>();
            for(Pair p : ppp) {
                int ga = get(p.a);
                if (!group.containsKey(ga))
                    group.put(ga, new ArrayList<Pair>());
                group.get(ga).add(p);
            }

            for(List<Pair> list : group.values()){
                int max = 0;
                for (int q = 0; q <list.size(); q++) {
                    Pair p = list.get(q);
                    max = Math.max(max, Math.max(maxV[p.a], maxH[p.b]));
                }
                max++;
                for (int q = 0; q < list.size(); q++) {
                    Pair p = list.get(q);
                    map[p.a*m+p.b] = max;
                    maxV[p.a] = Math.max(maxV[p.a], max);
                    maxH[p.b] = Math.max(maxH[p.b], max);
                }
            }

            for(Pair p : ppp){
                int a = p.a, b = p.b+n;
                tree[a] = a;
                tree[b] = b;
                height[a] = 0;
                height[b] = 0;
            }
        }

        for (int i = 0; i < n; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < m; j++) {
                if (sb.length() > 0) sb.append(' ');
                sb.append(map[i*m+j]);
            }
            io.writeLine(sb.toString());
        }
    }

    int[] tree;
    int[] height;

    int get(int c){
        while(tree[c]!=c)
            c = tree[c];
        return c;
    }

    long gcd(long a, long b) {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    }
}

class ConsoleIO {
    BufferedReader br;
    PrintWriter out;
    public ConsoleIO(){br = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);}
    public void flush(){this.out.close();}
    public void writeLine(String s) {this.out.println(s);}
    public void writeInt(int a) {this.out.print(a);this.out.print(' ');}
    public void writeWord(String s){
        this.out.print(s);
    }
    public String readLine() {try {return br.readLine();}catch (Exception ex){ return "";}}
    public long readLong() {
        return Long.parseLong(this.readLine());
    }
    public int readInt() {
        return Integer.parseInt(this.readLine().trim());
    }
    public long[] readLongArray() {
        String[]n=this.readLine().trim().split("\\s+");long[]r=new long[n.length];
        for(int i=0;i<n.length;i++)r[i]=Long.parseLong(n[i]);
        return r;
    }
    public int[] readIntArray() {
        String[]n=this.readLine().trim().split("\\s+");int[]r=new int[n.length];
        for(int i=0;i<n.length;i++)r[i]=Integer.parseInt(n[i]);
        return r;
    }
    public void writeIntArray(int[] a) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < a.length; i++) {if (i > 0) sb.append(' ');sb.append(a[i]);}
        this.writeLine(sb.toString());
    }
}


