Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

C. Table Compression

time limit per test

4 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputLittle 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*_{i, j} < *a*_{i, k}, then in the resulting table *a*'_{i, j} < *a*'_{i, k}, and if *a*_{i, j} = *a*_{i, k} then *a*'_{i, j} = *a*'_{i, k}. Similarly, if in some column *j* of the initial table *a*_{i, j} < *a*_{p, j} then in compressed table *a*'_{i, j} < *a*'_{p, j} and if *a*_{i, j} = *a*_{p, 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* (, the number of rows and the number of columns of the table respectively.

Each of the following *n* rows contain *m* integers *a*_{i, j} (1 ≤ *a*_{i, j} ≤ 10^{9}) 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 *a*_{1, 2} ≠ *a*_{21}, they are not located in the same row or column so they may become equal after the compression.

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/23/2017 04:14:00 (c4).

Desktop version, switch to mobile version.
User lists

Name |
---|