#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int ro[maxn];
int up(int u) { return (ro[u] == u) ? u : ro[u] = up(ro[u]); }
int me[maxn];
vector<int> no[maxn];
vector<pair<int, int> > q;
int o[maxn];
queue<int> s[2];
int main() {
  int n, m, t, k;
  scanf("%d%d", &n, &m);
  memset(o, 0, sizeof(o));
  memset(me, 0, sizeof(me));
  for (int x = 0; x < n * m; x++) {
    no[x].clear();
    scanf("%d", &me[x]);
    ro[x] = x;
  }
  for (int x = 0; x < n; x++) {
    q.clear();
    for (int y = 0; y < m; y++) {
      q.push_back(make_pair(me[x * m + y], y));
    }
    sort((q).begin(), (q).end());
    for (int y = 1; y < m; y++)
      if (q[y].first != q[y - 1].first) {
        no[x * m + q[y - 1].second].push_back(x * m + q[y].second);
        o[x * m + q[y].second]++;
      } else {
        ro[up(x * m + q[y - 1].second)] = up(x * m + q[y].second);
      }
  }
  for (int x = 0; x < m; x++) {
    q.clear();
    for (int y = 0; y < n; y++) {
      q.push_back(make_pair(me[y * m + x], y));
    }
    sort((q).begin(), (q).end());
    for (int y = 1; y < n; y++)
      if (q[y].first != q[y - 1].first) {
        no[q[y - 1].second * m + x].push_back(q[y].second * m + x);
        o[q[y].second * m + x]++;
      } else {
        ro[up(q[y - 1].second * m + x)] = up(q[y].second * m + x);
      }
  }
  int tem;
  int len;
  for (int x = 0; x < n * m; x++)
    if (x != up(x)) {
      tem = o[x];
      o[up(x)] += tem;
      o[x] -= tem;
      len = no[x].size();
      for (int y = 0; y < len; y++) no[up(x)].push_back(up(no[x][y]));
      vector<int>().swap(no[x]);
    } else {
      len = no[x].size();
      for (int y = 0; y < len; y++) no[x][y] = up(no[x][y]);
    }
  while (!s[0].empty()) s[0].pop();
  while (!s[1].empty()) s[1].pop();
  for (int x = 0; x < n * m; x++)
    if (x == ro[x] && o[x] == 0) {
      s[0].push(x);
    }
  t = 0;
  int f = 0;
  memset(me, 0, sizeof(me));
  while (!s[f].empty()) {
    t++;
    while (!s[f].empty()) {
      k = s[f].front();
      s[f].pop();
      me[k] = t;
      len = no[k].size();
      for (int x = 0; x < len; x++) {
        o[no[k][x]]--;
        if (o[no[k][x]] == 0) s[f ^ 1].push(no[k][x]);
      }
    }
    f ^= 1;
  }
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < m; y++) printf("%d ", me[up(x * m + y)]);
    putchar('\n');
  }
  return 0;
}
