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.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.function.IntBinaryOperator;

// Codeforces Round #345 (Div. 2)
// Table Compression
public class Problem_651_E {
    

    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        Problem_651_E solver = new Problem_651_E();
        solver.solve(1, new InputStreamReader(inputStream), out);
        out.close();
    }
    
    class UnionFind {
      int[] rank;

      int[] parent;

      int n;

      int count;

      UnionFind(int size)
      {
        count = size;
        n = size;
        rank = new int[n];
        parent = new int[n];
        for(int i = 0; i < n; i++)
          parent[i] = i;
      }

      void merge(int a, int b)
      {
        int pa = find(a);
        int pb = find(b);

        if(pa == pb)
          return;

        if(rank[pa] > rank[pb]) {
          parent[pb] = pa;
          rank[pb] += rank[pa];
        } else {
          parent[pa] = pb;
          rank[pa] += rank[pb];
        }
        count--;
      }

      int find(int a)
      {
        if(a != parent[a])
          parent[a] = find(parent[a]);
        return parent[a];
      }

      int count()
      {
        return count;
      }
    }

    static void siftdown(int[] h, int i, int n, int delta,
        IntBinaryOperator op)
    {
      if(i >= n)
        return;
      while(true) {
        int c = i * 2 + 1;
        if(c >= n)
          break;
        if(c + 1 < n) {
          if(op.applyAsInt(h[delta + c + 1], h[delta + c]) > 0)
            c++;
        }
        if(op.applyAsInt(h[delta + i], h[delta + c]) >= 0)
          break;
        int t = h[delta + c];
        h[delta + c] = h[delta + i];
        h[delta + i] = t;
        i = c;
      }
    }

    static void heapsort(int[] h, int l, int r, IntBinaryOperator op)
    {
      int length = r - l + 1;
      int delta = l;

      for(int j = length / 2; j >= 0; j--)
        siftdown(h, j, length, delta, op);
      for(int j = length - 1; j > 0; j--) {
        int t = h[delta];
        h[delta] = h[delta + j];
        h[delta + j] = t;
        siftdown(h, 0, j, delta, op);
      }
    }
    
    static void heapsort(int[] h, IntBinaryOperator op)
    {
      heapsort(h, 0, h.length - 1, op);
    }

    static class GraphUL {
      int n, m;

      ArrayList<Integer>[] adjacent;
      
      int[] deg;

      boolean oriented;

      GraphUL(int newn, int newm, boolean orient)
      {
        init(newn, newm, orient);
      }

      @SuppressWarnings("unchecked")
      void init(int newn, int newm, boolean orient)
      {
        oriented = orient;
        adjacent = new ArrayList[newn];
        deg = new int[newn];
        
        for(int i = 0; i < newn; ++i) {
          adjacent[i] = new ArrayList<>();
        }
        n = newn;
        m = newm >= 0 ? newm : n;
      }

      void addEdge(int u, int v)
      {
        assert (u < n && v < m);
        adjacent[u].add(v);
        deg[v]++;
        if(!oriented && u != v) {
          adjacent[v].add(u);
          deg[u]++;
        }
      }

      boolean oriented()
      {
        return oriented;
      }

      int size()
      {
        return n;
      }

      int size2()
      {
        return m;
      }

      ArrayList<Integer> edges(int v)
      {
        return adjacent[v];
      }
    }
    
    public void solve(int test, Reader input, PrintWriter out)
    {
        MyScanner in = new MyScanner(input);
        
        int n = in.nextInt();
        int m = in.nextInt();
        
        UnionFind uf = new UnionFind(n * m);
        
        int[] a = new int[n * m];
        
        for(int i = 0; i < n; i++) {
          for(int j = 0; j < m; j++) {
            a[i * m + j] = in.nextInt();
          }
        }

        int[] row = new int[m];
        int[] col = new int[n];
        
        IntBinaryOperator op = (x, y) -> a[x] - a[y];
        
        for(int i = 0; i < n; i++) {
          for(int j = 0; j < m; j++)
            row[j] = i * m + j;
          heapsort(row, op);
          for(int j = 1; j < m; j++)
            if(a[row[j]] == a[row[j-1]])
              uf.merge(row[j-1], row[j]);
        }
        
        for(int j = 0; j < m; j++) {
          for(int i = 0; i < n; i++)
            col[i] = i * m + j;
          heapsort(col, op);
          for(int i = 1; i < n; i++)
            if(a[col[i]] == a[col[i-1]])
              uf.merge(col[i-1], col[i]);
        }

        GraphUL g = new GraphUL(n * m, n * m, true);
        
        for(int i = 0; i < n; i++) {
          for(int j = 0; j < m; j++)
            row[j] = i * m + j;
          heapsort(row, op);
          for(int j = 1; j < m; j++)
            if(a[row[j]] > a[row[j-1]])
              g.addEdge(uf.find(row[j-1]), uf.find(row[j]));
        }
        
        for(int j = 0; j < m; j++) {
          for(int i = 0; i < n; i++)
            col[i] = i * m + j;
          heapsort(col, op);
          for(int i = 1; i < n; i++)
            if(a[col[i]] > a[col[i-1]])
              g.addEdge(uf.find(col[i-1]), uf.find(col[i]));
        }

        ArrayDeque<Integer> queue = new ArrayDeque<>();
        
        for(int i = 0; i < n * m; i++) {
          if(g.deg[i] == 0 && uf.find(i) == i)
            queue.add(i);
        }
        
        int[] dp = new int[n * m];
        
        while(!queue.isEmpty()) {
          int u = queue.pop();
          dp[u]++;
          
          for(int v : g.edges(u)) {
            dp[v] = Math.max(dp[v], dp[u]);
            g.deg[v]--;
            if(g.deg[v] == 0)
              queue.push(v);
          }
        }
        for(int i = 0; i < n; i++) {
          for(int j = 0; j < m; j++) {
            if(j > 0) out.print(' ');
            out.print(dp[uf.find(i * m + j)]);
          }
          out.println();
        }
    }

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner(Reader reader) {
            br = new BufferedReader(reader);
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        
        int[] nextIntArray(int n)
        {
            int[] r = new int[n];
            for(int i = 0; i < n; i++)
                r[i] = nextInt();
            return r;
        }

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------

}
