#include <bits/stdc++.h>
using namespace std;
int f[1000005], a[1000005], in[1000005], d[1000005];
pair<int, int> c[1000005];
int find(int x) {
  if (f[x] == x) return x;
  return f[x] = find(f[x]);
}
void uni(int x, int y) {
  int fx = find(x);
  int fy = find(y);
  f[fx] = fy;
}
vector<int> adj[1000005];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n * m; i++) {
    scanf("%d", &a[i]);
    f[i] = i;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) c[j] = make_pair(a[i * m + j], i * m + j);
    sort(c, c + m);
    int k = 0;
    while (k < m) {
      int p = k;
      while (p < m && c[p].first == c[k].first) {
        uni(c[p].second, c[k].second);
        p++;
      }
      k = p;
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) c[j] = make_pair(a[j * m + i], j * m + i);
    sort(c, c + n);
    int k = 0;
    while (k < n) {
      int p = k;
      while (p < n && c[p].first == c[k].first) {
        uni(c[p].second, c[k].second);
        p++;
      }
      k = p;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) c[j] = make_pair(a[i * m + j], i * m + j);
    sort(c, c + m);
    int k = 0;
    while (k < m) {
      int p = k;
      while (p < m && c[p].first == c[k].first) p++;
      if (p < m) {
        int fk = find(c[k].second), fp = find(c[p].second);
        adj[fk].push_back(fp);
        in[fp]++;
      }
      k = p;
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) c[j] = make_pair(a[j * m + i], j * m + i);
    sort(c, c + n);
    int k = 0;
    while (k < n) {
      int p = k;
      while (p < n && c[p].first == c[k].first) p++;
      if (p < n) {
        int fk = find(c[k].second), fp = find(c[p].second);
        adj[fk].push_back(fp);
        in[fp]++;
      }
      k = p;
    }
  }
  queue<int> q;
  for (int i = 0; i < n * m; i++)
    if (find(i) == i && in[i] == 0) {
      q.push(i);
      d[i] = 1;
    }
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < adj[x].size(); i++) {
      int y = adj[x][i];
      d[y] = max(d[y], d[x] + 1);
      in[y]--;
      if (in[y] == 0) q.push(y);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j) printf(" ");
      int num = d[find(i * m + j)];
      printf("%d", num);
    }
    printf("\n");
  }
}
