#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 4;
const int inf = (int)1e9 + 7;
const long double eps = 1e-7;
const int K = 21;
const int M = 1001;
struct cell {
  int val, x, y;
  cell() { x = 0, y = 0, val = 0; }
  cell(int val, int x, int y) : val(val), x(x), y(y) {}
  bool operator<(const cell &arg) const {
    if (val == arg.val) {
      if (x == arg.x) {
        return y < arg.y;
      }
      return x < arg.x;
    }
    return val < arg.val;
  }
};
vector<vector<vector<cell> > > g;
vector<vector<bool> > u;
vector<vector<int> > comp;
int sz;
int ans[N];
vector<vector<int> > an;
set<int> row[N], col[N];
vector<pair<vector<cell>, int> > comps;
void dfs(const cell &a) {
  u[a.x][a.y] = 1;
  comp[a.x][a.y] = sz;
  row[a.x].insert(sz);
  col[a.y].insert(sz);
  comps.back().first.push_back(a);
  for (cell &to : g[a.x][a.y]) {
    if (!u[to.x][to.y]) {
      dfs(to);
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<vector<cell> > a(n, vector<cell>(m));
  vector<vector<cell> > aa(m, vector<cell>(n));
  vector<cell> b(n * m);
  for (int i = 0; i < n; ++i) {
    g.push_back(vector<vector<cell> >(0));
    u.push_back(vector<bool>(m, 0));
    comp.push_back(vector<int>(m, 0));
    an.push_back(vector<int>(m, 0));
    for (int j = 0; j < m; ++j) {
      g[i].push_back(vector<cell>(0));
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[i][j].val);
      a[i][j].x = i, a[i][j].y = j;
      aa[j][i] = a[i][j];
      b[i * m + j] = a[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    sort(a[i].begin(), a[i].end());
    for (int j = 0; j < m; ++j) {
      if (j > 0 && a[i][j].val == a[i][j - 1].val) {
        g[a[i][j].x][a[i][j].y].push_back(a[i][j - 1]);
      }
      if (j < m - 1 && a[i][j].val == a[i][j + 1].val) {
        g[a[i][j].x][a[i][j].y].push_back(a[i][j + 1]);
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    sort(aa[i].begin(), aa[i].end());
    for (int j = 0; j < n; ++j) {
      if (j > 0 && aa[i][j].val == aa[i][j - 1].val) {
        g[aa[i][j].x][aa[i][j].y].push_back(aa[i][j - 1]);
      }
      if (j < n - 1 && aa[i][j].val == aa[i][j + 1].val) {
        g[aa[i][j].x][aa[i][j].y].push_back(aa[i][j + 1]);
      }
    }
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < n * m; ++i) {
    if (!u[b[i].x][b[i].y]) {
      comps.push_back(make_pair(vector<cell>(0), b[i].val));
      dfs(b[i]);
      sz++;
    }
  }
  for (int i = 0; i < sz; ++i) {
    int w = 0;
    for (cell &v : comps[i].first) {
      auto it = row[v.x].lower_bound(i);
      if (it != row[v.x].begin()) {
        --it;
        w = max(w, ans[*it]);
      }
      it = col[v.y].lower_bound(i);
      if (it != col[v.y].begin()) {
        --it;
        w = max(w, ans[*it]);
      }
    }
    ans[i] = w + 1;
    for (cell &v : comps[i].first) {
      an[v.x][v.y] = ans[i];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      printf("%d ", an[i][j]);
    }
    puts("");
  }
  return 0;
}
