#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int maxm = 1e5 + 10;
const long long inf = 1e15;
const int mod = 1e9 + 7;
int getint() {
  char c;
  while ((c = getchar()) && !(c >= '0' && c <= '9') && c != '-')
    ;
  int ret = c - '0', sgn = 0;
  if (c == '-') sgn = 1, ret = 0;
  while ((c = getchar()) && c >= '0' && c <= '9') ret = ret * 10 + c - '0';
  if (sgn) ret = -ret;
  return ret;
}
pair<int, int> g[maxn];
int r[maxn], c[maxn], f[maxn];
int findp(int x) {
  if (f[x] != x) return f[x] = findp(f[x]);
  return x;
}
int val[maxn], a[maxn];
int main() {
  int n, m;
  while (cin >> n >> m) {
    int N = n * m;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        a[(i - 1) * m + j] = getint();
      }
    }
    for (int i = 1; i <= N; i++) g[i] = make_pair(a[i], i), f[i] = i;
    sort(g + 1, g + N + 1);
    memset(val, 0, sizeof(val));
    memset(r, 0, sizeof(r));
    memset(c, 0, sizeof(c));
    int pos = g[1].second;
    int x = (pos - 1) / m + 1;
    int y = pos % m;
    if (y == 0) y = m;
    r[x] = c[y] = pos;
    val[pos] = 1;
    for (int i = 2; i <= N; i++) {
      int pos = g[i].second;
      int x = (pos - 1) / m + 1;
      int y = pos % m;
      if (y == 0) y = m;
      int xx = findp(r[x]), yy = findp(c[y]);
      if (a[pos] > a[xx] && a[pos] > a[yy]) {
        r[x] = c[y] = pos;
        val[pos] = max(val[xx] + 1, val[yy] + 1);
      } else if (a[pos] > a[xx] && a[pos] == a[yy]) {
        r[x] = pos;
        val[pos] = max(val[xx] + 1, val[yy]);
        f[yy] = pos;
      } else if (a[pos] == a[xx] && a[pos] > a[yy]) {
        c[y] = pos;
        val[pos] = max(val[xx], val[yy] + 1);
        f[xx] = pos;
      } else {
        r[x] = c[y] = pos;
        val[pos] = max(val[xx], val[yy]);
        f[xx] = pos, f[yy] = pos;
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (j > 1) printf(" ");
        int x = findp((i - 1) * m + j);
        printf("%d", val[x]);
      }
      puts("");
    }
  }
  return 0;
}
