#include <bits/stdc++.h>
template <class T>
inline void read(T &x) {
  char c;
  int f = 1;
  x = 0;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    f = -1;
  else
    x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= f;
}
int outn;
char out[10000000];
template <class T>
inline void write(T x) {
  if (x < 0) out[outn++] = '-', x = -x;
  if (x) {
    int tmpn = 0;
    char tmp[20] = {0};
    while (x) tmp[tmpn++] = x % 10 + '0', x /= 10;
    while (tmpn) out[outn++] = tmp[--tmpn];
  } else
    out[outn++] = '0';
}
using namespace std;
const int N = 1000000;
const int INF = 2e9;
int n, m;
vector<int> g[N + 9], ans[N + 9];
int id[N + 9], cur;
int fa[N + 9], rk[N + 9];
pair<int, vector<pair<int, int> > > h[N + 9];
int row[N + 9], line[N + 9];
int min1[N + 9], min2[N + 9];
inline bool cmp(const int &p, const int &q) {
  return g[cur][p] < g[cur][q] || (g[cur][p] == g[cur][q] && p < q);
}
inline bool cmp2(const int &p, const int &q) {
  return g[p][cur] < g[q][cur] || (g[p][cur] == g[q][cur] && p < q);
}
inline int find(int x) {
  int anc = x, y;
  while (anc != fa[anc]) anc = fa[anc];
  while (x != anc) y = fa[x], fa[x] = anc, x = y;
  return anc;
}
inline void merge(int x, int y) {
  x = find(x), y = find(y);
  if (x != y) {
    if (rk[x] > rk[y]) swap(x, y);
    rk[y] = max(rk[y], rk[x] + 1);
    fa[x] = y;
  }
}
int main() {
  read(n), read(m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int x;
      read(x);
      g[i].push_back(x);
      fa[i * m + j] = i * m + j;
      rk[i * m + j] = 1;
    }
    ans[i].resize(m);
  }
  for (int i = 0; i < n; ++i) {
    cur = i;
    for (int j = 0; j < m; ++j) id[j] = j;
    sort(id, id + m, cmp);
    for (int j = 0; j < m; ++j) {
      int k = j;
      while (k < m - 1 && g[i][id[k + 1]] == g[i][id[j]]) {
        ++k;
        merge(i * m + id[j], i * m + id[k]);
      }
      j = k;
    }
  }
  for (int j = 0; j < m; ++j) {
    cur = j;
    for (int i = 0; i < n; ++i) id[i] = i;
    sort(id, id + n, cmp2);
    for (int i = 0; i < n; ++i) {
      int k = i;
      while (k < n - 1 && g[id[k + 1]][j] == g[id[i]][j]) {
        ++k;
        merge(id[i] * m + j, id[k] * m + j);
      }
      i = k;
    }
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      h[find(i * m + j)].second.push_back(make_pair(i, j));
      h[find(i * m + j)].first = g[i][j];
    }
  sort(h, h + n * m);
  for (int i = 0; i < n * m; ++i)
    if (h[i].second.size()) {
      int mx = 0;
      for (int j = 0; j < h[i].second.size(); ++j) {
        mx = max(mx, min1[h[i].second[j].first]);
        mx = max(mx, min2[h[i].second[j].second]);
      }
      ++mx;
      for (int j = 0; j < h[i].second.size(); ++j) {
        min1[h[i].second[j].first] = mx;
        min2[h[i].second[j].second] = mx;
        ans[h[i].second[j].first][h[i].second[j].second] = mx;
      }
    }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) write(ans[i][j]), out[outn++] = ' ';
    out[outn++] = '\n';
  }
  puts(out);
  return 0;
}
