#include <bits/stdc++.h>
using namespace std;
const int maxn = 1111111;
int n, m;
int dat[maxn], ans[maxn], fa[maxn], rd[maxn], vis[maxn];
vector<int> nxt[maxn];
int father(int x) {
  if (fa[x] == x) return x;
  return fa[x] = father(fa[x]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cin >> n >> m;
  for (int i = 1; i <= n * m; ++i) cin >> dat[i], fa[i] = i;
  for (int i = 1; i <= n; ++i) {
    vector<pair<int, int>> v;
    for (int j = 1; j <= m; ++j) {
      int pos = (i - 1) * m + j;
      v.push_back(make_pair(dat[pos], pos));
    }
    sort(v.begin(), v.end());
    for (int j = 0; j < v.size() - 1; ++j) {
      if (v[j + 1].first == v[j].first)
        fa[father(v[j].second)] = father(v[j + 1].second);
    }
  }
  for (int i = 1; i <= m; ++i) {
    vector<pair<int, int>> v;
    for (int j = 1; j <= n; ++j) {
      int pos = (j - 1) * m + i;
      v.push_back(make_pair(dat[pos], pos));
    }
    sort(v.begin(), v.end());
    for (int j = 0; j < v.size() - 1; ++j) {
      if (v[j + 1].first == v[j].first)
        fa[father(v[j].second)] = father(v[j + 1].second);
    }
  }
  for (int i = 1; i <= n; ++i) {
    vector<pair<int, int>> v;
    for (int j = 1; j <= m; ++j) {
      int pos = (i - 1) * m + j;
      v.push_back(make_pair(dat[pos], pos));
    }
    sort(v.begin(), v.end());
    for (int j = 0; j < v.size() - 1; ++j) {
      if (v[j + 1].first == v[j].first) continue;
      nxt[father(v[j].second)].push_back(father(v[j + 1].second));
      rd[father(v[j + 1].second)]++;
    }
  }
  for (int i = 1; i <= m; ++i) {
    vector<pair<int, int>> v;
    for (int j = 1; j <= n; ++j) {
      int pos = (j - 1) * m + i;
      v.push_back(make_pair(dat[pos], pos));
    }
    sort(v.begin(), v.end());
    for (int j = 0; j < v.size() - 1; ++j) {
      if (v[j + 1].first == v[j].first) continue;
      nxt[father(v[j].second)].push_back(father(v[j + 1].second));
      rd[father(v[j + 1].second)]++;
    }
  }
  queue<int> q;
  for (int i = 1; i <= n * m; ++i)
    if (!rd[father(i)] && !vis[father(i)])
      q.push(fa[i]), vis[fa[i]] = 1, ans[fa[i]] = 1;
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    for (int x : nxt[t]) {
      rd[x]--;
      ans[x] = max(ans[x], ans[t] + 1);
      if (!rd[x]) q.push(x);
    }
  }
  for (int i = 1; i <= n * m; ++i) ans[i] = ans[father(i)];
  int js = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) cout << ans[++js] << ' ';
    cout << endl;
  }
}
