#include <bits/stdc++.h>
using namespace std;
struct obj {
  int i, j, p;
};
bool operator<(const obj &a, const obj &b) { return a.p < b.p; }
vector<int> pa, de, size;
vector<int> son;
vector<int> pans;
int n, m;
int find(int x) { return x == pa[x] ? x : pa[x] = find(pa[x]); }
int merge(int x, int y, int p) {
  x = find(x), y = find(y);
  if (x == y) return x;
  if (size[x] < size[y]) swap(x, y);
  pa[y] = de[x];
  son[de[x]] = y;
  de[x] = de[y];
  pans[x] = p;
  size[x] += size[y];
  return x;
}
int main() {
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  while (cin >> n >> m) {
    vector<vector<int>> arr(n, vector<int>(m));
    vector<obj> pt(n * m);
    vector<int> r(n, -1), c(m, -1);
    pa.clear();
    pa.resize(n * m);
    de.clear();
    de.resize(n * m);
    son.clear();
    son.resize(n * m);
    pans.clear();
    pans.resize(n * m, 0);
    size.clear();
    size.resize(n * m, 1);
    for (int i = 0, k = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> arr[i][j];
        pt[k++] = obj{i, j, arr[i][j]};
      }
    }
    sort(pt.begin(), pt.end());
    int p, pi, pj, mi, mj;
    for (int i = 0; i < n * m; i++) pa[i] = de[i] = son[i] = i;
    int index, curans;
    for (obj cur : pt) {
      int i, j;
      i = cur.i;
      j = cur.j;
      p = cur.p;
      pj = r[i];
      pi = c[j];
      mi = (pi == -1 ? 1
                     : (arr[pi][j] == p ? pans[find(pi * m + j)]
                                        : pans[find(pi * m + j)] + 1));
      mj = (pj == -1 ? 1
                     : (arr[i][pj] == p ? pans[find(i * m + pj)]
                                        : pans[find(i * m + pj)] + 1));
      curans = max(mi, mj);
      r[i] = j;
      c[j] = i;
      if (pi != -1 && pj != -1 && p == arr[i][pj] && p == arr[pi][j]) {
        index = merge(i * m + j, pi * m + j, curans);
        index = merge(index, i * m + pj, curans);
      } else if (pj != -1 && p == arr[i][pj])
        merge(i * m + j, i * m + pj, curans);
      else if (pi != -1 && p == arr[pi][j])
        merge(i * m + j, pi * m + j, curans);
      else
        pans[i * m + j] = curans;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) cout << pans[find(i * m + j)] << " ";
      cout << '\n';
    }
  }
  return 0;
}
