#include <bits/stdc++.h>
using namespace std;
struct graph {
  int fst[1000010], vv[5000020], nxt[5000020], e;
  void init() {
    memset(fst, -1, sizeof fst);
    e = 0;
  }
  void add(int u, int v) { vv[e] = v, nxt[e] = fst[u], fst[u] = e++; }
} go, gao;
struct node {
  int x, v;
  node(int x = 0, int v = 0) : x(x), v(v) {}
  bool operator<(const node &b) const { return v < b.v; }
};
int pre[1000010], sccno[1000010], dc, scnt;
stack<int> S;
int dfs(int u) {
  int lowu = pre[u] = ++dc;
  S.push(u);
  for (int i = go.fst[u]; ~i; i = go.nxt[i]) {
    int v = go.vv[i];
    if (!pre[v]) {
      int lowv = dfs(v);
      lowu = min(lowu, lowv);
    } else if (!sccno[v] && pre[v] < lowu)
      lowu = pre[v];
  }
  if (pre[u] == lowu) {
    ++scnt;
    while (1) {
      int x = S.top();
      S.pop();
      sccno[x] = scnt;
      if (x == u) break;
    }
  }
  return lowu;
}
vector<int> g[1000010];
node a[1000010];
int ans[1000010], in[1000010];
map<pair<int, int>, int> mp;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) g[i].resize(m);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      scanf("%d", &g[i][j]);
    }
  go.init();
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      a[j] = node(j, g[i][j]);
    }
    sort(a, a + m);
    for (int j = 1; j < m; ++j) {
      int u = i * m + a[j - 1].x, v = i * m + a[j].x;
      go.add(u, v);
      if (a[j].v == a[j - 1].v) {
        go.add(v, u);
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) a[j] = node(j, g[j][i]);
    sort(a, a + n);
    for (int j = 1; j < n; ++j) {
      int u = a[j - 1].x * m + i, v = a[j].x * m + i;
      go.add(u, v);
      if (a[j].v == a[j - 1].v) go.add(v, u);
    }
  }
  for (int i = 0; i < n * m; ++i)
    if (!pre[i]) dfs(i);
  memset(in, 0, sizeof in);
  mp.clear();
  gao.init();
  for (int u = 0; u < n * m; ++u) {
    for (int i = go.fst[u]; ~i; i = go.nxt[i]) {
      int v = go.vv[i];
      if (sccno[u] != sccno[v] && !mp.count(make_pair(sccno[u], sccno[v]))) {
        gao.add(sccno[u], sccno[v]);
        in[sccno[v]]++;
        mp[make_pair(sccno[u], sccno[v])]++;
      }
    }
  }
  queue<int> q;
  for (int i = 1; i <= scnt; ++i)
    if (in[i] == 0) q.push(i), ans[i] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = gao.fst[u]; ~i; i = gao.nxt[i]) {
      int v = gao.vv[i];
      in[v]--;
      if (in[v] == 0) q.push(v), ans[v] = ans[u] + 1;
    }
  }
  for (int i = 0; i < n * m; ++i) {
    printf("%d%c", ans[sccno[i]], (i + 1) % m == 0 ? '\n' : ' ');
  }
  return 0;
}
