#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
const long long INFll = 1ll * INF * INF;
const long double ldINF = 1e+018;
const long double EPS = 0.000000001;
const int base = INF;
vector<vector<int> > a, prev_row, prev_col;
vector<vector<pair<int, int> > > r, c;
vector<int> p;
int get(int v) { return (p[v] == v ? v : (p[v] = get(p[v]))); }
void unite(int x, int y) {
  if (rand() & 1) swap(x, y);
  if (x != y) p[x] = y;
}
int main() {
  srand(time(NULL));
  int n, m;
  scanf("%d%d", &n, &m);
  a.resize(n);
  r.resize(n);
  c.resize(m);
  prev_row.resize(n);
  prev_col.resize(m);
  p.resize(n * m);
  for (int i = 0; i < n * m; i++) p[i] = i;
  for (int i = 0; i < n; i++) {
    r[i].resize(m);
    a[i].resize(m);
    prev_row[i].resize(m, -1);
  }
  for (int i = 0; i < m; i++) {
    c[i].resize(n);
    prev_col[i].resize(n, -1);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
      r[i][j] = make_pair(a[i][j], j);
      c[j][i] = make_pair(a[i][j], i);
    }
  for (int i = 0; i < n; i++) {
    map<int, int> used;
    for (int j = 0; j < m; j++) {
      int v = a[i][j];
      int x = get(i * m + j);
      if (used[v] != 0) unite(x, used[v] - 1);
      x = get(i * m + j);
      used[v] = x + 1;
    }
  }
  for (int j = 0; j < m; j++) {
    map<int, int> used;
    for (int i = 0; i < n; i++) {
      int v = a[i][j];
      int x = get(i * m + j);
      if (used[v] != 0) unite(x, used[v] - 1);
      x = get(i * m + j);
      used[v] = x + 1;
    }
  }
  for (int i = 0; i < n; i++) sort(r[i].begin(), r[i].end());
  for (int i = 0; i < m; i++) sort(c[i].begin(), c[i].end());
  for (int i = 0; i < n; i++) {
    prev_row[i][r[i][0].second] = -1;
    for (int j = 1; j < m; j++)
      prev_row[i][r[i][j].second] = r[i][j - 1].second;
  }
  for (int i = 0; i < m; i++) {
    prev_col[i][c[i][0].second] = -1;
    for (int j = 1; j < n; j++)
      prev_col[i][c[i][j].second] = c[i][j - 1].second;
  }
  vector<pair<int, pair<int, int> > > v;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      v.push_back(make_pair(a[i][j], make_pair(i, j)));
  vector<vector<int> > b;
  b.resize(n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) b[i].push_back(get(i * m + j));
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    int x = v[i].second.first, y = v[i].second.second;
    int f, s;
    int zr, zc;
    if (prev_row[x][y] == -1)
      f = 1, zr = -1;
    else
      f = r[x][prev_row[x][y]].first + 1, zr = prev_row[x][y];
    if (prev_col[y][x] == -1)
      s = 1, zc = -1;
    else
      s = c[y][prev_col[y][x]].first + 1, zc = prev_col[y][x];
    if (zr != -1 && b[x][zr] == b[x][y]) f--;
    if (zc != -1 && b[zc][y] == b[x][y]) s--;
    a[x][y] = max(f, s);
    r[x][y].first = a[x][y];
    c[y][x].first = a[x][y];
  }
  bool ok = true;
  int k = 200;
  while (ok) {
    ok = false;
    vector<int> mx(n * m, 0);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        int x = b[i][j];
        mx[x] = max(mx[x], a[i][j]);
      }
    v.resize(0);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int x = b[i][j];
        a[i][j] = max(mx[x], a[i][j]);
        v.push_back(make_pair(a[i][j], make_pair(i, j)));
      }
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++) {
      int x = v[i].second.first, y = v[i].second.second;
      int upd;
      int prx = prev_row[x][y];
      int pry = prev_col[y][x];
      if (prx == -1 && pry == -1) continue;
      int f = -1;
      int z = b[x][y];
      if (prx != -1) {
        f = a[x][prx];
        if (b[x][prx] == z) f--;
      }
      int s = -1;
      if (pry != -1) {
        s = a[pry][y];
        if (b[pry][y] == z) s--;
      }
      upd = max(f, s);
      int w = a[x][y];
      a[x][y] = max(a[x][y], upd + 1);
      if (a[x][y] != w) ok = true;
    }
    k--;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) printf("%d ", a[i][j]);
    printf("\n");
  }
  return 0;
}
