#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 20;
vector<vector<int> > res;
struct point {
  int x, y;
  point() {}
  point(int a, int b) : x(a), y(b) {}
  bool operator<(const point &t) const { return x == t.x ? y < t.y : x < t.x; }
};
pair<int, point> p[N];
int fa[N], mx[N], my[N], mi[N], la[N];
void init(int n) {
  for (int i = 0; i < n; i++) fa[i] = i;
}
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void Union(int x, int y) {
  int fx = find(x), fy = find(y);
  fa[fx] = fy;
}
int main() {
  int n, m, x;
  cin >> n >> m;
  res.resize(n);
  for (int i = 0; i < n; i++) res[i].resize(m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%d", &x);
      p[i * m + j] = make_pair(x, point(i, j));
    }
  sort(p, p + n * m);
  init(n * m);
  memset(la, -1, sizeof(la));
  int l = 0, r = 0;
  while (l < n * m) {
    while (r < n * m && p[l].first == p[r].first) r++;
    for (int i = l; i < r; i++) {
      if (i > l && p[i].second.x == p[i - 1].second.x) Union(i, i - 1);
      if (~la[p[i].second.y]) Union(i, la[p[i].second.y]);
      la[p[i].second.y] = i;
    }
    for (int i = l; i < r; i++) {
      int t = find(i);
      mi[t] = max(mi[t], mx[p[i].second.x]);
      mi[t] = max(mi[t], my[p[i].second.y]);
    }
    for (int i = l; i < r; i++) {
      int t = find(i);
      int x = p[i].second.x, y = p[i].second.y;
      res[x][y] = mi[t] + 1;
      mx[x] = mi[t] + 1;
      my[y] = mi[t] + 1;
    }
    while (l < r) la[p[l++].second.y] = -1;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      printf("%d%c", res[i][j], j == m - 1 ? '\n' : ' ');
  return 0;
}
