#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
struct UnionFind {
  vector<long long> data;
  UnionFind(long long size) : data(size, -1) {}
  bool unionSet(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool findSet(long long x, long long y) { return root(x) == root(y); }
  long long root(long long x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  long long size(long long x) { return -data[root(x)]; }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  vector<vector<long long> > A(N, vector<long long>(M));
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }
  UnionFind uf(N * M);
  vector<vector<long long> > g(N * M);
  vector<long long> C(N * M, 0);
  for (long long i = 0; i < N; i++) {
    vector<pair<long long, long long> > vp(M);
    for (long long j = 0; j < M; j++) {
      vp[j] = make_pair(A[i][j], i * M + j);
    }
    sort(vp.begin(), vp.end());
    for (long long j = 1; j < M; j++) {
      if (vp[j - 1].first == vp[j].first) {
        uf.unionSet(vp[j - 1].second, vp[j].second);
      }
    }
  }
  for (long long i = 0; i < M; i++) {
    vector<pair<long long, long long> > vp(N);
    for (long long j = 0; j < N; j++) {
      vp[j] = make_pair(A[j][i], j * M + i);
    }
    sort(vp.begin(), vp.end());
    for (long long j = 1; j < N; j++) {
      if (vp[j - 1].first == vp[j].first) {
        uf.unionSet(vp[j - 1].second, vp[j].second);
      }
    }
  }
  for (long long i = 0; i < N; i++) {
    vector<pair<long long, long long> > vp(M);
    for (long long j = 0; j < M; j++) {
      vp[j] = make_pair(A[i][j], uf.root(i * M + j));
    }
    sort(vp.begin(), vp.end());
    for (long long j = 1; j < M; j++) {
      if (vp[j - 1].first == vp[j].first) {
      } else {
        g[vp[j - 1].second].push_back(vp[j].second);
        C[vp[j].second]++;
      }
    }
  }
  for (long long i = 0; i < M; i++) {
    vector<pair<long long, long long> > vp(N);
    for (long long j = 0; j < N; j++) {
      vp[j] = make_pair(A[j][i], uf.root(j * M + i));
    }
    sort(vp.begin(), vp.end());
    for (long long j = 1; j < N; j++) {
      if (vp[j - 1].first == vp[j].first) {
      } else {
        g[vp[j - 1].second].push_back(vp[j].second);
        C[vp[j].second]++;
      }
    }
  }
  queue<long long> qu;
  vector<long long> res(N * M);
  for (long long i = 0; i < N * M; i++) {
    if (C[i] == 0) {
      qu.push(i);
      res[i] = 1;
    }
  }
  while (qu.size() > 0) {
    long long a = qu.front();
    qu.pop();
    for (long long i : g[a]) {
      C[i]--;
      res[i] = max(res[i], res[a] + 1);
      if (C[i] == 0) {
        qu.push(i);
      }
    }
  }
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < M; j++) {
      if (j > 0) cout << " ";
      cout << res[uf.root(i * M + j)];
    }
    cout << endl;
  }
}
