#include <bits/stdc++.h>
using namespace std;
struct data {
  int x, y;
};
map<int, vector<data> > v;
vector<vector<int> > M;
int Row[1000010];
int Col[1000010];
int ans[1000010];
int pa[2000010];
int find(int x) {
  if (x == pa[x]) return x;
  return pa[x] = find(pa[x]);
}
void merge(int p, int q) {
  p = find(p);
  q = find(q);
  if (p != q) {
    pa[p] = q;
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int key;
      scanf("%d", &key);
      data p;
      p.x = i;
      p.y = j;
      v[key].push_back(p);
    }
  }
  M.resize(n);
  for (int i = 0; i < n; i++) M[i].resize(m);
  for (int i = 0; i < n + m; i++) pa[i] = i;
  for (auto i : v) {
    int val = 0;
    for (auto j : i.second) {
      merge(j.x, j.y + n);
    }
    for (auto j : i.second) {
      int x = find(j.x);
      ans[x] = max(ans[x], max(Row[j.x], Col[j.y]));
    }
    for (auto j : i.second) {
      M[j.x][j.y] = ans[find(j.x)] + 1;
      Row[j.x] = M[j.x][j.y];
      Col[j.y] = M[j.x][j.y];
    }
    for (auto j : i.second) {
      ans[j.x] = 0;
      ans[j.y + n] = 0;
      pa[j.x] = j.x;
      pa[j.y + n] = j.y + n;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%d ", M[i][j]);
    }
    printf("\n");
  }
}
