#include <bits/stdc++.h>
using namespace std;
bool used[10000001];
int n, m, second = 0, ds[1000001], ans[1000001], str[1000001], sv[1000001];
struct o {
  int x, i, j;
};
o d[1000001];
vector<vector<int> > a;
bool comp(o a, o b) {
  if (a.x == b.x) return a.i < b.i;
  return a.x < b.x;
}
bool fcomp(o a, o b) {
  if (a.x == b.x) return a.j < b.j;
  return a.x < b.x;
}
int FS(int v) {
  if (ds[v] == v) return v;
  return ds[v] = FS(ds[v]);
}
void US(int a, int b) {
  a = FS(a);
  b = FS(b);
  ds[a] = ds[b];
  return;
}
vector<pair<int, int> > tt[1000001];
pair<int, int> dd(int v) {
  int i = (v - 1) / m;
  ++i;
  int j = v % m;
  if (j == 0) j = m;
  return {i, j};
}
int main() {
  cin >> n >> m;
  a.resize(n + 1);
  for (int k = 1; k <= n; ++k) {
    a[k].resize(m + 1);
  }
  for (int k = 1; k <= n; ++k)
    for (int i = 1; i <= m; ++i) {
      cin >> a[k][i];
      ds[(k - 1) * m + i] = (k - 1) * m + i;
      o w;
      w.x = a[k][i];
      w.i = k;
      w.j = i;
      d[++second] = w;
    }
  sort(d + 1, d + second + 1, comp);
  for (int k = 1; k < second; ++k)
    if (d[k].x == d[k + 1].x) {
      if (d[k].i == d[k + 1].i)
        US((d[k].i - 1) * m + d[k].j, (d[k + 1].i - 1) * m + d[k + 1].j);
    }
  sort(d + 1, d + second + 1, fcomp);
  for (int k = 1; k < second; ++k)
    if (d[k].x == d[k + 1].x) {
      if (d[k].j == d[k + 1].j) {
        US((d[k].i - 1) * m + d[k].j, (d[k + 1].i - 1) * m + d[k + 1].j);
      }
    }
  for (int k = 1; k <= n * m; ++k) tt[FS(ds[k])].push_back(dd(k));
  for (int k = 1; k <= second; ++k) {
    int i = d[k].i;
    int j = d[k].j;
    if (used[(i * m - m) + j]) continue;
    int cm = FS(ds[(i * m - m) + j]);
    int cnt = 0;
    for (int i = 0; i < tt[cm].size(); ++i) {
      int ii = tt[cm][i].first;
      int jj = tt[cm][i].second;
      used[ii * (m)-m + jj] = 1;
      cnt = max(str[ii], cnt);
      cnt = max(sv[jj], cnt);
    }
    for (int i = 0; i < tt[cm].size(); ++i) {
      int ii = tt[cm][i].first;
      int jj = tt[cm][i].second;
      ans[ii * (m)-m + jj] = cnt + 1;
      sv[jj] = max(cnt + 1, sv[jj]);
      str[ii] = max(cnt + 1, str[ii]);
    }
  }
  for (int k = 1; k <= n; ++k) {
    for (int i = 1; i <= m; ++i) cout << ans[(k - 1) * m + i] << ' ';
    cout << endl;
  }
  return 0;
}
