#include <bits/stdc++.h>
using namespace std;
struct DSU {
  vector<int> par;
  DSU(int n = 0) { par.assign(n, -1); }
  int get_set(int x) { return par[x] < 0 ? x : par[x] = get_set(par[x]); }
  bool union_set(int x, int y) {
    assert(0 <= x && x < ((int)(par).size()));
    assert(0 <= y && y < ((int)(par).size()));
    x = get_set(x);
    y = get_set(y);
    assert(0 <= x && x < ((int)(par).size()));
    assert(0 <= y && y < ((int)(par).size()));
    if (x == y) {
      return false;
    }
    if (-par[x] > -par[y]) {
      swap(x, y);
    }
    par[y] += par[x];
    par[x] = y;
    return true;
  }
};
vector<vector<int> > a;
int n, m;
bool read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return false;
  }
  a.assign(n, vector<int>(m, 0));
  for (int i = 0; i < (int)n; ++i)
    for (int j = 0; j < (int)m; ++j) {
      scanf("%d", &a[i][j]);
    }
  return true;
}
int code(int i, int j) { return i * m + j; }
void dfs(int v, vector<int>& was, DSU& dsu, vector<int>& order,
         const vector<vector<int> >& g) {
  if (dsu.get_set(v) != v || was[v]) {
    return;
  }
  was[v] = true;
  assert(0 <= v && v < ((int)(g).size()));
  for (int to : g[v]) {
    if (was[to]) {
      continue;
    }
    dfs(to, was, dsu, order, g);
  }
  order.push_back(v);
}
void solve() {
  DSU dsu(n * m);
  for (int i = 0; i < (int)n; ++i) {
    vector<pair<int, int> > cur;
    for (int j = 0; j < (int)m; ++j) {
      cur.push_back(make_pair(a[i][j], j));
    }
    sort(begin(cur), end(cur));
    int l = 0;
    while (l < ((int)(cur).size())) {
      int r = l;
      while (r < ((int)(cur).size()) && cur[l].first == cur[r].first) ++r;
      for (int z = l; z + 1 < r; ++z) {
        int j = cur[z].second;
        int next_j = cur[z + 1].second;
        dsu.union_set(code(i, j), code(i, next_j));
      }
      l = r;
    }
  }
  for (int j = 0; j < (int)m; ++j) {
    vector<pair<int, int> > cur;
    for (int i = 0; i < (int)n; ++i) {
      cur.push_back(make_pair(a[i][j], i));
    }
    sort(begin(cur), end(cur));
    int l = 0;
    while (l < ((int)(cur).size())) {
      int r = l;
      while (r < ((int)(cur).size()) && cur[l].first == cur[r].first) ++r;
      for (int z = l; z + 1 < r; ++z) {
        int i = cur[z].second;
        int next_i = cur[z + 1].second;
        dsu.union_set(code(i, j), code(next_i, j));
      }
      l = r;
    }
  }
  vector<vector<int> > gt(n * m);
  vector<vector<int> > g(n * m);
  for (int i = 0; i < (int)n; ++i) {
    vector<pair<int, int> > cur;
    for (int j = 0; j < (int)m; ++j) {
      cur.push_back(make_pair(a[i][j], j));
    }
    sort(begin(cur), end(cur));
    int l = 0;
    while (l < ((int)(cur).size())) {
      int r = l;
      while (r < ((int)(cur).size()) && cur[l].first == cur[r].first) ++r;
      if (r < ((int)(cur).size())) {
        int j = cur[l].second;
        int next_j = cur[r].second;
        int from = dsu.get_set(code(i, j));
        int to = dsu.get_set(code(i, next_j));
        gt[to].push_back(from);
        g[from].push_back(to);
      }
      l = r;
    }
  }
  for (int j = 0; j < (int)m; ++j) {
    vector<pair<int, int> > cur;
    for (int i = 0; i < (int)n; ++i) {
      cur.push_back(make_pair(a[i][j], i));
    }
    sort(begin(cur), end(cur));
    int l = 0;
    while (l < ((int)(cur).size())) {
      int r = l;
      while (r < ((int)(cur).size()) && cur[l].first == cur[r].first) ++r;
      if (r < ((int)(cur).size())) {
        int i = cur[l].second;
        int next_i = cur[r].second;
        int from = dsu.get_set(code(i, j));
        int to = dsu.get_set(code(next_i, j));
        gt[to].push_back(from);
        g[from].push_back(to);
      }
      l = r;
    }
  }
  vector<int> was(n * m, 0);
  vector<int> order;
  for (int v = 0; v < (int)n * m; ++v) {
    dfs(v, was, dsu, order, g);
  }
  reverse(begin(order), end(order));
  vector<vector<int> > val(n, vector<int>(m, 1));
  for (int v : order) {
    int i = v / m;
    int j = v % m;
    int V = dsu.get_set(v);
    for (int from : gt[V]) {
      int fi = from / m;
      int fj = from % m;
      val[i][j] = max(val[i][j], val[fi][fj] + 1);
    }
  }
  for (int v = 0; v < (int)n * m; ++v) {
    int i = v / m;
    int j = v % m;
    int V = dsu.get_set(v);
    int I = V / m;
    int J = V % m;
    val[i][j] = val[I][J];
  }
  for (int i = 0; i < (int)n; ++i) {
    for (int j = 0; j < (int)m; ++j) {
      printf("%d ", val[i][j]);
    }
    printf("\n");
  }
}
int main() {
  while (read()) {
    solve();
  }
  return 0;
}
