#include <bits/stdc++.h>
using namespace std;
struct st {
  int x;
  int y;
  int in;
};
bool compx(st a, st b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }
bool compy(st a, st b) { return a.y == b.y ? a.x < b.x : a.y < b.y; }
int ar[1000006];
int br[1000006];
map<int, int> M;
vector<int> ans[1000006];
int n, m;
vector<st> X[1000006];
int mx[1000006];
int my[1000006];
int par[1000006];
int mv[1000006];
int find_parent(int i) {
  if (par[i] == i) return i;
  return par[i] = find_parent(par[i]);
}
bool do_union(int i, int j) {
  int pi = find_parent(i);
  int pj = find_parent(j);
  if (pi == pj) return false;
  par[pj] = pi;
  return true;
}
int main() {
  int a, b, c, d, e, x, y, z;
  scanf("%d %d", &n, &m);
  M.clear();
  z = 0;
  for (a = 0; a < n; a++) {
    for (b = 0; b < m; b++) {
      scanf("%d", &ar[z]);
      br[z] = ar[z];
      X[z].clear();
      z++;
      ans[a].push_back(0);
    }
  }
  sort(br, br + z);
  e = 1;
  M[br[0]] = e;
  for (a = 1; a < z; a++) {
    if (br[a] != br[a - 1]) M[br[a]] = ++e;
  }
  for (a = 0; a < z; a++) ar[a] = M[ar[a]];
  e = 0;
  st second;
  for (a = 0; a < n; a++) {
    for (b = 0; b < m; b++) {
      second.in = e + 1;
      second.x = a;
      second.y = b;
      X[ar[e]].push_back(second);
      par[e + 1] = e + 1;
      e++;
    }
  }
  for (d = 0; d < n * m; d++) {
    if (d > 0) {
      if (br[d] == br[d - 1]) continue;
    }
    e = M[br[d]];
    sort(X[e].begin(), X[e].end(), compx);
    for (a = 0; a < X[e].size(); a++) {
      mv[X[e][a].in] = max(mx[X[e][a].x], my[X[e][a].y]) + 1;
      if (a + 1 < X[e].size()) {
        if (X[e][a].x == X[e][a + 1].x) {
          do_union(X[e][a].in, X[e][a + 1].in);
        }
      }
    }
    sort(X[e].begin(), X[e].end(), compy);
    for (a = 0; a < X[e].size(); a++) {
      if (a + 1 < X[e].size()) {
        if (X[e][a].y == X[e][a + 1].y) {
          do_union(X[e][a].in, X[e][a + 1].in);
        }
      }
    }
    for (a = 0; a < X[e].size(); a++) {
      b = find_parent(X[e][a].in);
      mv[b] = max(mv[b], mv[X[e][a].in]);
    }
    for (a = 0; a < X[e].size(); a++) {
      b = par[X[e][a].in];
      mx[X[e][a].x] = mv[b];
      my[X[e][a].y] = mv[b];
      ans[X[e][a].x][X[e][a].y] = mv[b];
    }
  }
  for (a = 0; a < n; a++) {
    for (b = 0; b < m; b++) printf("%d ", ans[a][b]);
    printf("\n");
  }
  return 0;
}
