#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
inline int max(int a, int b) { return a < b ? b : a; }
inline int min(int a, int b) { return a > b ? b : a; }
inline long long max(long long a, long long b) { return a < b ? b : a; }
inline long long min(long long a, long long b) { return a > b ? b : a; }
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const long long inf = 1e18;
long long power(long long a, long long n) {
  if (n == 0) {
    return 1;
  }
  long long b = power(a, n / 2);
  b = b * b % mod;
  if (n % 2) b = b * a % mod;
  return b;
}
int add(int a, int b) { return (a + b) % mod; }
int mul(int a, int b) { return (long long)a * b % mod; }
vector<int> A[N], vis[N];
vector<pair<int, int> > R[N], C[N];
int row[N], col[N], visR[N], visC[N];
vector<pair<int, int> > Q, U, V;
void solve() {
  for (int i = 0; i < U.size(); ++i) {
    R[U[i].first].push_back(U[i]);
    C[U[i].second].push_back(U[i]);
  }
  for (int i = 0; i < U.size(); ++i) {
    if (!vis[U[i].first][U[i].second]) {
      int mx = 0;
      int in = 0;
      Q.push_back(U[i]);
      vis[U[i].first][U[i].second] = 1;
      while (in < (int)Q.size()) {
        pair<int, int> a = Q[in];
        in++;
        mx = max(mx, max(row[a.first], col[a.second]));
        if (!visR[a.first])
          for (int j = 0; j < R[a.first].size(); ++j) {
            if (!vis[R[a.first][j].first][R[a.first][j].second]) {
              vis[R[a.first][j].first][R[a.first][j].second] = 1;
              Q.push_back(R[a.first][j]);
            }
          }
        if (!visC[a.second])
          for (int j = 0; j < C[a.second].size(); ++j) {
            if (!vis[C[a.second][j].first][C[a.second][j].second]) {
              vis[C[a.second][j].first][C[a.second][j].second] = 1;
              Q.push_back(C[a.second][j]);
            }
          }
        visR[a.first] = 1;
        visC[a.second] = 1;
      }
      for (int j = 0; j < Q.size(); ++j) {
        A[Q[j].first][Q[j].second] = mx + 1;
        row[Q[j].first] = col[Q[j].second] = mx + 1;
      }
      Q.clear();
    }
  }
  for (int i = 0; i < U.size(); ++i) {
    R[U[i].first].clear();
    C[U[i].second].clear();
    vis[U[i].first][U[i].second] = 0;
    visR[U[i].first] = visC[U[i].second] = 0;
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) A[i].resize(m), vis[i].resize(m);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) vis[i][j] = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      int x;
      scanf("%d", &x);
      A[i][j] = x;
      V.push_back(make_pair(x, i * m + j));
    }
  sort(V.begin(), V.end());
  int p = V[0].first;
  for (int i = 0; i < n * m; ++i) {
    if (V[i].first == p)
      U.push_back(make_pair(V[i].second / m, V[i].second % m));
    else {
      solve();
      U.clear();
      U.push_back(make_pair(V[i].second / m, V[i].second % m));
      p = V[i].first;
    }
  }
  solve();
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      printf("%d ", A[i][j]);
    }
    printf("\n");
  }
  return 0;
}
