#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 10;
const int maxv = 1e3 + 10;
const double eps = 1e-9;
int a[maxn];
int ans[maxn];
int deg[maxn];
int par[maxn];
int n, m;
int Find(int u) {
  if (u == par[u]) return u;
  return par[u] = Find(par[u]);
}
bool same(int u, int v) { return Find(u) == Find(v); }
void unit(int u, int v) {
  u = Find(u);
  v = Find(v);
  par[u] = v;
}
int id(int i, int j) { return Find(i * m + j); }
struct sta {
  int val, id;
  sta(int _val = 0, int _id = 0) : val(_val), id(_id) {}
  bool operator<(const sta& rhs) const { return val < rhs.val; }
  bool operator==(const sta& rhs) const { return val == rhs.val; }
};
bool vis[maxn];
std::vector<int> G[maxn];
int main() {
  scanf("%d%d", &n, &m);
  int all = n * m;
  for (int i = 0; i < all; i++) {
    par[i] = i;
  }
  std::vector<std::vector<int> > a(n);
  std::vector<std::vector<sta> > row(n);
  std::vector<std::vector<sta> > col(m);
  std::vector<sta>::iterator st, ed;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x;
      scanf("%d", &x);
      a[i].push_back(x);
      row[i].push_back(sta(x, j));
    }
    sort(row[i].begin(), row[i].end());
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      col[j].push_back(sta(a[i][j], i));
    }
    sort(col[j].begin(), col[j].end());
  }
  for (int i = 0; i < n; i++) {
    int u = id(i, row[i][0].id);
    int kid = 0;
    for (int j = 1; j < row[i].size(); j++) {
      int v = id(i, row[i][j].id);
      if (a[i][row[i][kid].id] == a[i][row[i][j].id])
        unit(u, v);
      else {
        u = v;
        kid = j;
      }
    }
  }
  for (int j = 0; j < m; j++) {
    int u = id(col[j][0].id, j);
    int kid = 0;
    for (int i = 1; i < col[j].size(); i++) {
      int v = id(col[j][i].id, j);
      if (a[col[j][kid].id][j] == a[col[j][i].id][j]) {
        unit(u, v);
      } else {
        u = v;
        kid = i;
      }
    }
  }
  for (int i = 0; i < n; i++)
    row[i].resize(unique(row[i].begin(), row[i].end()) - row[i].begin());
  for (int j = 0; j < m; j++)
    col[j].resize(unique(col[j].begin(), col[j].end()) - col[j].begin());
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int u = id(i, j);
      st = upper_bound(row[i].begin(), row[i].end(), sta(a[i][j], j));
      ed = row[i].end();
      if (st != ed) {
        int v = id(i, st->id);
        G[u].push_back(v);
        deg[v]++;
      }
      st = upper_bound(col[j].begin(), col[j].end(), sta(a[i][j], i));
      ed = col[j].end();
      if (st != ed) {
        int v = id(st->id, j);
        G[u].push_back(v);
        deg[v]++;
      }
    }
  }
  queue<int> que;
  for (int i = 0; i < all; i++) {
    int u = Find(i);
    if (vis[u]) continue;
    vis[u] = 1;
    if (deg[u] == 0) que.push(u);
  }
  while (que.size()) {
    int u = que.front();
    que.pop();
    ans[u] = max(1, ans[u]);
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (--deg[v] == 0) {
        ans[v] = max(ans[u] + 1, ans[v]);
        que.push(v);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%d ", ans[id(i, j)]);
    }
    puts("");
  }
  return 0;
}
