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 *a*<sub class="lower-index">*i*, *j*</sub> &lt; *a*<sub class="lower-index">*i*, *k*</sub>, then in the resulting table *a*'<sub class="lower-index">*i*, *j*</sub> &lt; *a*'<sub class="lower-index">*i*, *k*</sub>, and if *a*<sub class="lower-index">*i*, *j*</sub> = *a*<sub class="lower-index">*i*, *k*</sub> then *a*'<sub class="lower-index">*i*, *j*</sub> = *a*'<sub class="lower-index">*i*, *k*</sub>. Similarly, if in some column *j* of the initial table *a*<sub class="lower-index">*i*, *j*</sub> &lt; *a*<sub class="lower-index">*p*, *j*</sub> then in compressed table *a*'<sub class="lower-index">*i*, *j*</sub> &lt; *a*'<sub class="lower-index">*p*, *j*</sub> and if *a*<sub class="lower-index">*i*, *j*</sub> = *a*<sub class="lower-index">*p*, *j*</sub> then *a*'<sub class="lower-index">*i*, *j*</sub> = *a*'<sub class="lower-index">*p*, *j*</sub>. 

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.
The first line of the input contains two integers *n* and *m* (<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8ce9eb3b66e2ccbb79eae736994b3703b3b8e7d2.png" style="max-width: 100.0%;max-height: 100.0%;"/>, the number of rows and the number of columns of the table respectively.

Each of the following *n* rows contain *m* integers *a*<sub class="lower-index">*i*, *j*</sub> (1 ≤ *a*<sub class="lower-index">*i*, *j*</sub> ≤ 10<sup class="upper-index">9</sup>) that are the values in the table.
In the first sample test, despite the fact *a*<sub class="lower-index">1, 2</sub> ≠ *a*<sub class="lower-index">21</sub>, they are not located in the same row or column so they may become equal after the compression.
import random
import sys
from math import gcd, lcm, sqrt, isqrt, perm
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce, cmp_to_key
from itertools import accumulate, combinations, permutations
from heapq import nsmallest, nlargest, heappushpop, heapify, heappop, heappush
from copy import deepcopy
from bisect import bisect_left, bisect_right
from string import ascii_lowercase, ascii_uppercase
inf = float('inf')
input = lambda: sys.stdin.readline().strip()
I = lambda: input()
II = lambda: int(input())
MII = lambda: map(int, input().split())
LI = lambda: list(input().split())
LII = lambda: list(map(int, input().split()))
GMI = lambda: map(lambda x: int(x) - 1, input().split())
LGMI = lambda: list(map(lambda x: int(x) - 1, input().split()))
MOD = 10**9+7


class UnionFind:
    def __init__(self, n):
        self.fa = list(range(n))

    def find(self, x):
        t = x
        while self.fa[x] != x:
            x = self.fa[x]
        while t != x:
            t, self.fa[t] = self.fa[t], x
        return x

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            self.fa[x] = self.fa[y]

    def reset(self, x):
        self.fa[x] = x

def solve():
    m, n = MII()
    matrix = []
    for i in range(m):
        matrix.append(LII())
    m, n = len(matrix), len(matrix[0])
    d = defaultdict(list)
    for i, row in enumerate(matrix):
        for j, x in enumerate(row):
            d[x].append((i, j))
    row_max, col_max = [0] * m, [0] * n
    res = [[0] * n for _ in range(m)]
    rank = Counter()
    uf = UnionFind(m + n)
    for x in sorted(d):
        rank = Counter()
        for i, j in d[x]:
            uf.union(i, j + m)
        for i, j in d[x]:
            rank[uf.find(i)] = max(rank[uf.find(i)], row_max[i], col_max[j])
        for i, j in d[x]:
            res[i][j] = row_max[i] = col_max[j] = 1 + rank[uf.find(i)]
        for i, j in d[x]:
            uf.reset(i)
            uf.reset(j + m)
    for i in range(m):
        print(*res[i])
    return

solve()
