#include <bits/stdc++.h>
using namespace std;
struct data {
  int v, r, c;
  data(int a, int b, int x) : v(a), r(b), c(x) {}
  bool operator<(const data &B) const { return v < B.v; }
};
int R, C, WH, mark[1000005], maxVal[1000005], matrix[1000005];
vector<int> adj[1000005];
vector<data> number;
void dfs1(int nd) {
  if (mark[nd]) return;
  mark[nd] = 1;
  WH = max(WH, maxVal[nd]);
  for (int i = 0; i < (adj[nd].size()); i++) dfs1(adj[nd][i]);
}
void dfs2(int nd) {
  if (mark[nd] == 2) return;
  mark[nd] = 2;
  maxVal[nd] = WH + 1;
  for (int i = 0; i < (adj[nd].size()); i++) {
    int ch = adj[nd][i];
    if (nd < R) matrix[nd * C + ch - R] = WH + 1;
    dfs2(ch);
  }
}
void put(vector<int> &curSet) {
  for (int i = 0; i < (curSet.size()); i++) {
    int nd = curSet[i];
    if (mark[nd]) continue;
    WH = 0;
    dfs1(nd);
    dfs2(nd);
  }
  for (int i = 0; i < (curSet.size()); i++) mark[curSet[i]] = 0;
}
int main() {
  scanf("%d%d", &R, &C);
  for (int i = 0; i < (R); i++)
    for (int j = 0; j < (C); j++) {
      int v;
      scanf("%d", &v);
      number.push_back(data(v, i, j));
    }
  sort(number.begin(), number.end());
  vector<int> curSet;
  for (int i = 0; i < (number.size()); i++) {
    if (i && number[i].v != number[i - 1].v) {
      put(curSet);
      for (int j = 0; j < (curSet.size()); j++) adj[curSet[j]].clear();
      curSet.clear();
    }
    curSet.push_back(number[i].r);
    curSet.push_back(R + number[i].c);
    adj[number[i].r].push_back(R + number[i].c);
    adj[R + number[i].c].push_back(number[i].r);
  }
  put(curSet);
  for (int i = 0; i < (R); i++) {
    for (int j = 0; j < (C); j++) {
      if (j) printf(" ");
      printf("%d", matrix[i * C + j]);
    }
    puts("");
  }
  return 0;
}
