#include <bits/stdc++.h>
#pragma GCC push_options
#pragma GCC optimize("O3")
using namespace std;
vector<vector<int>> a;
vector<vector<char>> found;
vector<vector<vector<pair<int, int>>>> gr;
vector<pair<int, int>> c;
void comp(int x, int y) {
  if (found[x][y]) return;
  found[x][y] = true;
  c.emplace_back(x, y);
  for (auto p : gr[x][y]) {
    comp(p.first, p.second);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  a.assign(n, vector<int>(m));
  found.assign(n, vector<char>(m, 0));
  gr.assign(n, vector<vector<pair<int, int>>>(m));
  vector<pair<int, pair<int, int>>> all;
  for (auto& b : a)
    for (auto& x : b) scanf("%d", &x);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      all.emplace_back(a[i][j], pair<int, int>(i, j));
    }
  }
  map<int, int> prevs;
  for (int i = 0; i < n; ++i) {
    prevs.clear();
    for (int j = 0; j < m; ++j) {
      auto it = prevs.find(a[i][j]);
      if (it != prevs.end()) {
        gr[i][j].emplace_back(i, it->second);
        gr[i][it->second].emplace_back(i, j);
      }
      prevs[a[i][j]] = j;
    }
  }
  for (int i = 0; i < m; ++i) {
    prevs.clear();
    for (int j = 0; j < n; ++j) {
      auto it = prevs.find(a[j][i]);
      if (it != prevs.end()) {
        gr[j][i].emplace_back(it->second, i);
        gr[it->second][i].emplace_back(j, i);
      }
      prevs[a[j][i]] = j;
    }
  }
  sort(all.begin(), all.end());
  vector<int> minx(n, 0);
  vector<int> miny(m, 0);
  vector<int> oldminx(n, 0);
  vector<int> oldminy(m, 0);
  vector<vector<int>> b(n, vector<int>(m, -1));
  for (int i = 0; i < all.size(); ++i) {
    int val = all[i].first;
    int x = all[i].second.first;
    int y = all[i].second.second;
    if (b[x][y] != -1) continue;
    c.clear();
    comp(x, y);
    int best = 0;
    for (auto p : c) {
      if (oldminx[p.first] == val)
        best = max(minx[p.first], best);
      else
        best = max(minx[p.first] + 1, best);
      if (oldminy[p.second] == val)
        best = max(miny[p.second], best);
      else
        best = max(miny[p.second] + 1, best);
    }
    for (auto p : c) {
      b[p.first][p.second] = best;
      minx[p.first] = best;
      miny[p.second] = best;
      oldminx[p.first] = val;
      oldminy[p.second] = val;
    }
  }
  for (auto& c : b) {
    for (auto& x : c) cout << x << " ";
    cout << endl;
  }
}
