#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
const int maxn = 1000000;
int n, m;
vector<int> a[maxn + 5];
vector<int> ans[maxn + 5];
vector<pair<int, int> > all;
inline bool cmp(const pair<int, int> &first, const pair<int, int> &second) {
  return a[first.first][first.second] < a[second.first][second.second];
}
inline bool cmp0(const pair<int, int> &first, const pair<int, int> &second) {
  return first.first < second.first;
}
inline bool cmp1(const pair<int, int> &first, const pair<int, int> &second) {
  return first.second < second.second;
}
int Maxcol[maxn + 5], Maxrow[maxn + 5];
int fa[maxn + 5];
inline int get(int first) {
  return fa[first] == first ? first : fa[first] = get(fa[first]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (0), _end_ = (n); i < _end_; ++i) {
    a[i].resize(m);
    ans[i].resize(m);
    for (int j = (0), _end_ = (m); j < _end_; ++j)
      scanf("%d", &a[i][j]), all.push_back(make_pair(i, j));
  }
  for (int i = (0), _end_ = (n * m); i < _end_; ++i) fa[i] = i;
  sort((all).begin(), (all).end(), cmp);
  memset(Maxrow, 0, sizeof Maxrow);
  memset(Maxcol, 0, sizeof Maxcol);
  static int val[maxn + 5];
  memset(val, 0, sizeof val);
  for (int i = 0; i < (int((all).size()));) {
    int j = i;
    while (j < (int((all).size())) &&
           a[all[j].first][all[j].second] == a[all[i].first][all[i].second])
      ++j;
    sort(all.begin() + i, all.begin() + j, cmp0);
    for (int k = (i), _end_ = (j - 1); k < _end_; ++k)
      if (all[k + 1].first == all[k].first)
        fa[get(all[k + 1].first * m + all[k + 1].second)] =
            get(all[k].first * m + all[k].second);
    sort(all.begin() + i, all.begin() + j, cmp1);
    for (int k = (i), _end_ = (j - 1); k < _end_; ++k)
      if (all[k + 1].second == all[k].second)
        fa[get(all[k + 1].first * m + all[k + 1].second)] =
            get(all[k].first * m + all[k].second);
    for (int k = (i), _end_ = (j); k < _end_; ++k)
      chkmax(val[get(all[k].first * m + all[k].second)],
             max(Maxrow[all[k].first], Maxcol[all[k].second]));
    for (int k = (i), _end_ = (j); k < _end_; ++k)
      ans[all[k].first][all[k].second] =
          val[get(all[k].first * m + all[k].second)];
    for (int k = (i), _end_ = (j); k < _end_; ++k) {
      chkmax(Maxrow[all[k].first], ans[all[k].first][all[k].second] + 1);
      chkmax(Maxcol[all[k].second], ans[all[k].first][all[k].second] + 1);
    }
    i = j;
  }
  for (int i = (0), _end_ = (n); i < _end_; ++i) {
    for (int j = (0), _end_ = (m); j < _end_; ++j) printf("%d ", ans[i][j] + 1);
    printf("\n");
  }
  return 0;
}
