#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int>> parent[1000001], hv[1000001], vv[1000001];
vector<vector<pair<int, int>>> edges[1000001];
vector<int> vals[1000001], done[1000001];
pair<int, int> get(pair<int, int> x) {
  pair<int, int> k = parent[x.first][x.second];
  if (parent[k.first][k.second] == k)
    return k;
  else
    return parent[k.first][k.second] = get(k);
}
void unite(pair<int, int> a, pair<int, int> c) {
  a = get(a), c = get(c);
  if (a == c) return;
  parent[c.first][c.second] = a;
}
int dp(pair<int, int> x) {
  x = get(x);
  if (edges[x.first][x.second].size() == 0) return 1;
  if (done[x.first][x.second]) return done[x.first][x.second];
  sort(edges[x.first][x.second].begin(), edges[x.first][x.second].end());
  edges[x.first][x.second].erase(
      unique(edges[x.first][x.second].begin(), edges[x.first][x.second].end()),
      edges[x.first][x.second].end());
  int ans = 0;
  for (pair<int, int> i : edges[x.first][x.second]) ans = max(ans, dp(i));
  return done[x.first][x.second] = (ans + 1);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++)
    parent[i].resize(n), edges[i].resize(n), vals[i].resize(n),
        done[i].resize(n);
  for (int j = 0; j < n; j++)
    for (int i = 0; i < m; i++) {
      pair<int, int> x = make_pair(i, j);
      scanf("%d", &vals[x.first][x.second]), parent[x.first][x.second] = x;
      vv[i].push_back(make_pair(vals[x.first][x.second], j)),
          hv[j].push_back(make_pair(vals[x.first][x.second], i));
    }
  for (int i = 0; i < m; i++) {
    sort(vv[i].begin(), vv[i].end());
    for (int j = 0; j < n - 1; j++)
      if (vv[i][j].first == vv[i][j + 1].first)
        unite(make_pair(i, vv[i][j].second), make_pair(i, vv[i][j + 1].second));
  }
  for (int j = 0; j < n; j++) {
    sort(hv[j].begin(), hv[j].end());
    for (int i = 0; i < m - 1; i++)
      if (hv[j][i].first == hv[j][i + 1].first)
        unite(make_pair(hv[j][i].second, j), make_pair(hv[j][i + 1].second, j));
  }
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n - 1; j++)
      if (vv[i][j].first < vv[i][j + 1].first) {
        pair<int, int> a = get(make_pair(i, vv[i][j + 1].second));
        pair<int, int> c = get(make_pair(i, vv[i][j].second));
        edges[a.first][a.second].push_back(c);
      }
  for (int j = 0; j < n; j++)
    for (int i = 0; i < m - 1; i++)
      if (hv[j][i].first < hv[j][i + 1].first) {
        pair<int, int> a = get(make_pair(hv[j][i + 1].second, j));
        pair<int, int> c = get(make_pair(hv[j][i].second, j));
        edges[a.first][a.second].push_back(c);
      }
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < m; i++) printf("%d ", dp(make_pair(i, j)));
    printf("\n");
  }
  return 0;
}
