#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > v;
vector<int> vv;
int m;
map<int, vector<pair<int, int> > > mp;
int X[1000002];
int Y[1000002];
vector<pair<int, int> > VV;
map<int, vector<pair<int, int> > > XX;
map<int, vector<pair<int, int> > > YY;
vector<vector<int> > ans;
queue<pair<int, int> > q;
inline void bfs(pair<int, int> f, int vv) {
  q.push(f);
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    ans[x][y] = vv;
    X[x] = max(X[x], vv);
    Y[y] = max(Y[y], vv);
    for (auto it = XX[x].begin(); it != XX[x].end(); it++) {
      int xx = (*it).first;
      int yy = (*it).second;
      if (ans[xx][yy] != -1) {
        continue;
      }
      ans[xx][yy] = 0;
      q.push(make_pair(xx, yy));
    }
    for (auto it = YY[y].begin(); it != YY[y].end(); it++) {
      int xx = (*it).first;
      int yy = (*it).second;
      if (ans[xx][yy] != -1) {
        continue;
      }
      ans[xx][yy] = 0;
      q.push(make_pair(xx, yy));
    }
    XX[x].clear();
    YY[y].clear();
  }
}
int main() {
  cin >> n >> m;
  vv.assign(m, 0);
  v.assign(n, vv);
  vv.assign(m, -1);
  ans.assign(n, vv);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &v[i][j]);
      mp[v[i][j]].push_back(make_pair(i, j));
    }
  }
  for (auto it = mp.begin(); it != mp.end(); it++) {
    vector<pair<int, int> > &V = (*it).second;
    int SIZE = V.size();
    VV.clear();
    XX.clear();
    YY.clear();
    for (int i = 0; i < SIZE; i++) {
      int val = max(X[V[i].first], Y[V[i].second]);
      XX[V[i].first].push_back(make_pair(V[i].first, V[i].second));
      YY[V[i].second].push_back(make_pair(V[i].first, V[i].second));
      VV.push_back(make_pair(val + 1, i));
    }
    sort(VV.begin(), VV.end());
    reverse(VV.begin(), VV.end());
    for (int i = 0; i < SIZE; i++) {
      int ind = VV[i].second;
      int re = VV[i].first;
      int x = V[ind].first;
      int y = V[ind].second;
      if (ans[x][y] != -1) {
        continue;
      }
      bfs(make_pair(x, y), re);
    }
  }
  int anss = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j) {
        printf(" ");
      }
      printf("%d", ans[i][j]);
    }
    puts("");
  }
  return 0;
}
