#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
pair<int, pair<int, int> > a[N];
map<int, int> X;
map<int, int> Y;
int f[N], ans[N], Hx[N], Hy[N];
int Find(int x) {
  if (f[x] == x) return x;
  return f[x] = Find(f[x]);
}
void un(int x, int y) {
  int fx = Find(x), fy = Find(y);
  if (fx != fy) f[fx] = fy;
}
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    X.clear(), Y.clear();
    for (int i = 0; i < n * m; i++) {
      f[i] = i;
      scanf("%d", &a[i].first);
      a[i].second.first = i / m;
      a[i].second.second = i % m;
    }
    int j = -1;
    sort(a, a + n * m);
    for (int i = 0; i < n * m; i++) {
      if (i != n * m - 1 && a[i].first == a[i + 1].first) continue;
      for (int k = j + 1; k <= i; k++) {
        int p = a[k].second.first * m + a[k].second.second;
        int x = a[k].second.first, y = a[k].second.second;
        Hx[x] = p;
        Hy[y] = p;
      }
      for (int k = j + 1; k <= i; k++) {
        int p = a[k].second.first * m + a[k].second.second;
        int x = a[k].second.first, y = a[k].second.second;
        un(Hx[x], p);
        un(Hy[y], p);
      }
      for (int k = j + 1; k <= i; k++) {
        int p = a[k].second.first * m + a[k].second.second;
        int x = a[k].second.first, y = a[k].second.second;
        ans[Find(p)] = max(ans[Find(p)], max(X[x], Y[y]) + 1);
      }
      for (int k = j + 1; k <= i; k++) {
        int p = a[k].second.first * m + a[k].second.second;
        int x = a[k].second.first, y = a[k].second.second;
        X[x] = max(X[x], ans[Find(p)]);
        Y[y] = max(Y[y], ans[Find(p)]);
      }
      j = i;
    }
    for (int i = 0; i < n * m; i++)
      printf("%d%c", ans[Find(i)], i % m == m - 1 ? '\n' : ' ');
  }
  return 0;
}
