#include <bits/stdc++.h>
using namespace std;
const long long INF = 1 << 28;
const long long LINF = 1ll << 61;
inline long long getnum() {
  register long long r = 0;
  register bool ng = 0;
  register char c;
  c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') ng = 1, c = getchar();
  while (c != ' ' && c != '\n') r = r * 10 + c - '0', c = getchar();
  if (ng) r = -r;
  return r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline void putsp() { putchar(' '); }
inline void putendl() { putchar('\n'); }
inline char mygetchar() {
  register char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
int n, m;
vector<pair<int, pair<int, int> > > v;
int row[1000111], col[1000111];
vector<pair<pair<int, int>, int> > mat;
int ans[1000111];
vector<int> con[3000111];
bool vis[3000111], mk[3000111];
void add_edge(int x, int y) {
  con[x].push_back(y);
  con[y].push_back(x);
}
int dfs1(int x) {
  mk[x] = 1;
  vis[x] = 1;
  int t = 0;
  if (x <= 1000000)
    t = max(row[v[x].second.first] + 1, col[v[x].second.second] + 1);
  for (int i = 0; i < con[x].size(); i++) {
    if (!vis[con[x][i]]) {
      t = max(t, dfs1(con[x][i]));
    }
  }
  return t;
}
void dfs2(int x, int t) {
  vis[x] = 0;
  if (x <= 1000000) ans[x] = t;
  for (int i = 0; i < con[x].size(); i++) {
    if (vis[con[x][i]]) {
      dfs2(con[x][i], t);
    }
  }
}
int main() {
  n = getnum(), m = getnum();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x;
      x = getnum();
      v.push_back(make_pair(x, make_pair(i, j)));
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size();) {
    int r = i;
    while (r < v.size() && v[r].first == v[i].first) r++;
    int mx = 1;
    for (int j = i; j < r; j++) {
      add_edge(j, 1000000 + v[j].second.first);
      add_edge(j, 2000000 + v[j].second.second);
    }
    for (int j = i; j < r; j++)
      if (!mk[j]) dfs2(j, dfs1(j));
    for (int j = i; j < r; j++) {
      con[1000000 + v[j].second.first].clear();
      con[2000000 + v[j].second.second].clear();
      row[v[j].second.first] = ans[j];
      col[v[j].second.second] = ans[j];
      mat.push_back(make_pair(v[j].second, ans[j]));
    }
    i = r;
  }
  sort(mat.begin(), mat.end());
  for (int i = 0; i < mat.size(); i++) {
    putnum(mat[i].second), putsp();
    if ((i + 1) % m == 0) putchar('\n');
  }
  return 0;
}
