#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 4e18;
const long double pai = acos(-1);
int n, m;
int f(int x, int y) { return x * m + y; }
vector<int> v[1000009], g[1000009];
int deg[1000009], p[1000009], val[1000009];
int get(int node) {
  if (node == p[node]) return node;
  return p[node] = get(p[node]);
}
void merge(int a, int b) {
  a = get(a), b = get(b);
  if (a == b) return;
  if (g[a].size() < g[b].size()) swap(a, b);
  for (auto u : g[b]) g[a].push_back(u);
  g[b].clear();
  p[b] = a;
}
void topo() {
  queue<int> q;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x = get(f(i, j));
      if (deg[x] == 0 && x == f(i, j)) {
        q.push(x);
      }
    }
  }
  while (q.size()) {
    int node = q.front();
    int X = val[node];
    q.pop();
    for (auto u : g[node]) {
      if (deg[u] == 0) continue;
      deg[u]--;
      val[u] = max(val[u], X + 1);
      if (deg[u] == 0) q.push(u);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    v[i].resize(m + 9);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &v[i][j]);
      int x = f(i, j);
      p[x] = x;
    }
  }
  for (int i = 0; i < n; i++) {
    vector<pair<int, int> > ret;
    for (int j = 0; j < m; j++) {
      ret.push_back({v[i][j], f(i, j)});
    }
    sort(ret.begin(), ret.end());
    for (int j = 0; j < ret.size() - 1; j++) {
      int a = ret[j].first, A = ret[j].second;
      int b = ret[j + 1].first, B = ret[j + 1].second;
      if (a == b) merge(A, B);
    }
  }
  for (int j = 0; j < m; j++) {
    vector<pair<int, int> > ret;
    for (int i = 0; i < n; i++) {
      ret.push_back({v[i][j], f(i, j)});
    }
    sort(ret.begin(), ret.end());
    for (int i = 0; i < ret.size() - 1; i++) {
      int a = ret[i].first, A = ret[i].second;
      int b = ret[i + 1].first, B = ret[i + 1].second;
      if (a == b) merge(A, B);
    }
  }
  for (int i = 0; i < n; i++) {
    vector<pair<int, int> > ret;
    for (int j = 0; j < m; j++) {
      ret.push_back({v[i][j], f(i, j)});
    }
    sort(ret.begin(), ret.end());
    for (int j = 0; j < ret.size() - 1; j++) {
      int a = ret[j].first, A = ret[j].second;
      int b = ret[j + 1].first, B = ret[j + 1].second;
      if (a < b) {
        A = get(A);
        B = get(B);
        deg[B]++;
        g[A].push_back(B);
      }
    }
  }
  for (int j = 0; j < m; j++) {
    vector<pair<int, int> > ret;
    for (int i = 0; i < n; i++) {
      ret.push_back({v[i][j], f(i, j)});
    }
    sort(ret.begin(), ret.end());
    for (int i = 0; i < ret.size() - 1; i++) {
      int a = ret[i].first, A = ret[i].second;
      int b = ret[i + 1].first, B = ret[i + 1].second;
      if (a < b) {
        A = get(A);
        B = get(B);
        deg[B]++;
        g[A].push_back(B);
      }
    }
  }
  topo();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%d ", val[get(f(i, j))] + 1);
    }
    printf("\n");
  }
}
