#include <bits/stdc++.h>
using namespace std;
int *f;
int find(int ix) { return f[ix] == ix ? ix : f[ix] = find(f[ix]); }
void join(int ia, int ib) { f[find(ia)] = find(ib); }
int main() {
  int n, m, c;
  int *a, *nr, *nc, *res;
  vector<pair<int, int> > vp;
  vector<int> *e, *rev;
  scanf("%d %d", &n, &m);
  c = n * m;
  a = new int[c + 1];
  res = new int[c + 1]();
  nr = new int[n + 1];
  nc = new int[m + 1];
  e = new vector<int>[c + 1]();
  rev = new vector<int>[c + 1]();
  f = new int[c + 1];
  memset(nr, -1, sizeof(int) * (n + 1));
  memset(nc, -1, sizeof(int) * (m + 1));
  for (auto i = 0; i < c; i++) {
    scanf("%d", a + i);
    vp.push_back(pair<int, int>(a[i], i));
    f[i] = i;
  }
  sort(vp.begin(), vp.end());
  for (auto i = 0; i < c; i++) {
    int x = vp[i].second / m, y = vp[i].second % m;
    if (nr[x] != -1) {
      if (a[nr[x]] == vp[i].first)
        join(vp[i].second, nr[x]);
      else
        e[vp[i].second].push_back(nr[x]);
    }
    if (nc[y] != -1) {
      if (a[nc[y]] == vp[i].first)
        join(vp[i].second, nc[y]);
      else
        e[vp[i].second].push_back(nc[y]);
    }
    nr[x] = nc[y] = vp[i].second;
  }
  for (auto i = 0; i < c; i++) rev[find(i)].push_back(i);
  for (auto i = 0; i < c; i++)
    if (find(vp[i].second) == vp[i].second) {
      int ret = 0, ix = vp[i].second;
      for (auto j : rev[ix])
        for (auto k : e[j]) ret = max(ret, res[k]);
      for (auto j : rev[ix]) res[j] = ret + 1;
    }
  for (auto i = 0; i < c; i++) {
    printf("%d ", res[i]);
    if ((i + 1) % m == 0) printf("\n");
  }
  return 0;
}
