#include <bits/stdc++.h>
using namespace std;
struct Node {
  int n;
  int x;
  int y;
  int num;
} po[1000001] = {};
int fa[1000001] = {};
int ans[1000001] = {};
struct pp {
  int d;
  int num;
} d[1000001];
vector<int> e[1000001];
queue<int> q;
int fan[1000001];
int n, m;
int num;
bool cmp(Node a, Node b) {
  if (a.x != b.x) return a.x < b.x;
  return a.n < b.n;
}
bool cmp2(Node a, Node b) {
  if (a.y != b.y) return a.y < b.y;
  return a.n < b.n;
}
bool cmp3(pp a, pp b) { return a.d < b.d; }
int ff(int x) {
  if (x == fa[x]) return x;
  fa[x] = ff(fa[x]);
  return fa[x];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      num++;
      scanf("%d", &po[num].n);
      po[num].x = i;
      po[num].y = j;
      po[num].num = num;
      fa[num] = num;
      d[num].num = num;
    }
  }
  sort(po + 1, po + num + 1, cmp);
  for (int i = 2; i <= num; i++) {
    if (po[i].n == po[i - 1].n && po[i].x == po[i - 1].x) {
      fa[ff(po[i].num)] = ff(po[i - 1].num);
    }
  }
  sort(po + 1, po + num + 1, cmp2);
  for (int i = 2; i <= num; i++) {
    if (po[i].n == po[i - 1].n && po[i].y == po[i - 1].y) {
      fa[ff(po[i].num)] = ff(po[i - 1].num);
    }
  }
  sort(po + 1, po + num + 1, cmp);
  for (int i = 2; i <= num; i++) {
    if (po[i].n > po[i - 1].n && po[i].x == po[i - 1].x) {
      e[ff(po[i - 1].num)].push_back(ff(po[i].num));
      d[ff(po[i].num)].d++;
    }
  }
  sort(po + 1, po + num + 1, cmp2);
  for (int i = 2; i <= num; i++) {
    if (po[i].n > po[i - 1].n && po[i].y == po[i - 1].y) {
      e[ff(po[i - 1].num)].push_back(ff(po[i].num));
      d[ff(po[i].num)].d++;
    }
  }
  sort(d + 1, d + num + 1, cmp3);
  for (int i = 1; i <= num; i++) {
    if (fa[d[i].num] == d[i].num && d[i].d == 0) {
      q.push(d[i].num);
    }
    fan[d[i].num] = i;
  }
  int t;
  while (!q.empty()) {
    t = q.front();
    if (ans[t] == 0) ans[t] = 1;
    vector<int>::iterator j;
    for (j = e[t].begin(); j != e[t].end(); j++) {
      ans[*j] = max(ans[*j], ans[t] + 1);
      d[fan[*j]].d--;
      if (d[fan[*j]].d == 0) q.push(*j);
    }
    q.pop();
  }
  num = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      num++;
      if (ans[num] == 0) ans[num] = ans[ff(num)];
      printf("%d ", ans[num]);
    }
    printf("\n");
  }
  return 0;
}
