#include <bits/stdc++.h>
using namespace std;
using ld = double;
using ll = long long;
using ull = unsigned long long;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int SZ = 1 << 13;
char buff[SZ], *pos = buff + SZ - 1;
inline ll read() {
  ll x = 0;
  int f = 1,
      c = (++pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos);
  for (; !isdigit(c);
       c = (++pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos))
    if (c == '-') f = -f;
  for (; isdigit(c);
       c = (++pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos))
    x = (x << 3) + (x << 1) + (c ^ 48);
  return x * f;
}
const int N = 1 << 20;
int n, m;
vector<vector<int> > a;
vector<int> v, lst;
vector<int> g[N];
int dis[N];
int in[N];
int P(int i, int j) { return i * m + j; }
struct Dsu {
  int par[N];
  Dsu() {
    for (int i = 0; i < N; ++i) par[i] = i;
  }
  int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
  void merge(int x, int y) { par[find(x)] = find(y); }
} dsu;
int main() {
  n = read(), m = read();
  a.resize(n);
  for (int i = 0; i < n; ++i) a[i].resize(m);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) a[i][j] = read();
  for (int i = 0; i < n; ++i) {
    v.clear();
    for (int j = 0; j < m; ++j) v.push_back(a[i][j]);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    lst.resize(v.size());
    for (int j = 0; j < (int)v.size(); ++j) lst[j] = -1;
    for (int j = 0; j < m; ++j) {
      int ii = lower_bound(v.begin(), v.end(), a[i][j]) - v.begin();
      if (~lst[ii]) dsu.merge(P(i, j), lst[ii]);
      lst[ii] = P(i, j);
    }
  }
  for (int i = 0; i < m; ++i) {
    v.clear();
    for (int j = 0; j < n; ++j) v.push_back(a[j][i]);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    lst.resize(v.size());
    for (int j = 0; j < (int)v.size(); ++j) lst[j] = -1;
    for (int j = 0; j < n; ++j) {
      int ii = lower_bound(v.begin(), v.end(), a[j][i]) - v.begin();
      if (~lst[ii]) dsu.merge(P(j, i), lst[ii]);
      lst[ii] = P(j, i);
    }
  }
  for (int i = 0; i < n; ++i) {
    v.clear();
    for (int j = 0; j < m; ++j) v.push_back(a[i][j]);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    lst.resize(v.size());
    for (int j = 0; j < (int)v.size(); ++j) lst[j] = -1;
    for (int j = 0; j < m; ++j) {
      int ii = lower_bound(v.begin(), v.end(), a[i][j]) - v.begin();
      if (~lst[ii]) continue;
      lst[ii] = dsu.find(P(i, j));
    }
    for (int j = 1; j < (int)v.size(); ++j) {
      g[lst[j - 1]].push_back(lst[j]);
      in[lst[j]]++;
    }
  }
  for (int i = 0; i < m; ++i) {
    v.clear();
    for (int j = 0; j < n; ++j) v.push_back(a[j][i]);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    lst.resize(v.size());
    for (int j = 0; j < (int)v.size(); ++j) lst[j] = -1;
    for (int j = 0; j < n; ++j) {
      int ii = lower_bound(v.begin(), v.end(), a[j][i]) - v.begin();
      if (~lst[ii]) continue;
      lst[ii] = dsu.find(P(j, i));
    }
    for (int j = 1; j < (int)v.size(); ++j) {
      g[lst[j - 1]].push_back(lst[j]);
      in[lst[j]]++;
    }
  }
  queue<int> q;
  for (int i = 0; i < n * m; ++i)
    if (!in[i]) dis[i] = 1, q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < (int)g[u].size(); ++i) {
      int v = g[u][i];
      --in[v];
      if (dis[v] < dis[u] + 1) dis[v] = dis[u] + 1;
      if (!in[v]) {
        q.push(v);
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      printf("%d ", dis[dsu.find(P(i, j))]);
    }
    puts("");
  }
  return 0;
}
