#include <bits/stdc++.h>
using namespace std;
int chh;
const int N = 1000005;
int n, m, tol;
int f[N], b[N], c[N];
pair<int, int> w[N], v[N];
vector<int> g[N];
queue<pair<int, int> > q;
void init() {
  tol = n * m;
  for (int i = 0; i < (tol); i++) f[i] = i, g[i].clear();
  memset(c, 0, sizeof(c));
}
int find(int x) { return x == f[x] ? f[x] : f[x] = find(f[x]); }
int main() {
  int x, y, id, l, r, e;
  while (~scanf("%d %d", &n, &m)) {
    init();
    for (int i = 0; i < (n); i++)
      for (int j = 0; j < (m); j++) scanf("%d", &b[i * m + j]);
    e = 0;
    for (int i = 0; i < (n); i++) {
      for (int j = 0; j < (m); j++) {
        id = i * m + j;
        w[e++] = make_pair(b[id], id);
      }
      l = i * m, r = (i + 1) * m;
      sort(w + l, w + r);
      for (int k = (l); k <= (r - 1); k++) {
        x = find(w[k].second);
        while (k + 1 < r && w[k + 1].first == w[k].first)
          f[find(w[++k].second)] = x;
      }
    }
    e = 0;
    for (int j = 0; j < (m); j++) {
      for (int i = 0; i < (n); i++) {
        id = i * m + j;
        v[e++] = make_pair(b[id], id);
      }
      l = j * n, r = (j + 1) * n;
      sort(v + l, v + r);
      for (int k = (l); k <= (r - 1); k++) {
        x = find(v[k].second);
        while (k + 1 < r && v[k + 1].first == v[k].first)
          f[find(v[++k].second)] = x;
      }
    }
    for (int i = 0; i < (n); i++) {
      l = i * m, r = (i + 1) * m;
      for (int k = (l); k <= (r - 2); k++) {
        if (w[k].first == w[k + 1].first) continue;
        x = find(w[k].second), y = find(w[k + 1].second);
        g[x].push_back(y), c[y]++;
      }
    }
    for (int j = 0; j < (m); j++) {
      l = j * n, r = (j + 1) * n;
      for (int k = (l); k <= (r - 2); k++) {
        if (v[k].first == v[k + 1].first) continue;
        x = find(v[k].second), y = find(v[k + 1].second);
        g[x].push_back(y), c[y]++;
      }
    }
    for (int i = 0; i < (tol); i++)
      if (find(i) == i && c[i] == 0) q.push(make_pair(i, 1));
    while (!q.empty()) {
      x = q.front().first, y = q.front().second;
      q.pop(), b[x] = y;
      for (__typeof__((g[x]).begin()) it = (g[x]).begin(); it != (g[x]).end();
           it++) {
        if (--c[*it] == 0) q.push(make_pair(*it, y + 1));
      }
    }
    for (int i = 0; i < (n); i++) {
      for (int j = 0; j < (m); j++) printf("%d ", b[f[i * m + j]]);
      puts("");
    }
  }
  return 0;
}
