#include <bits/stdc++.h>
using namespace std;
vector<int> a[1000005], v[1000005];
vector<pair<int, int> > b;
int fa[1000005];
int d[1000005];
bool in[1000005];
int dist[1000005];
int n, m;
int get(int x, int y) { return (x - 1) * m + y; }
bool cmp(pair<int, int> x, pair<int, int> y) {
  return a[x.first][x.second] < a[y.first][y.second];
}
int find(int x) {
  if (fa[x] == x) return x;
  return fa[x] = find(fa[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n * m; i++) fa[i] = i;
  for (int i = 1; i <= n; i++) {
    a[i].push_back(0);
    for (int j = 1; j <= m; j++) {
      int x;
      scanf("%d", &x);
      a[i].push_back(x);
    }
  }
  for (int i = 1; i <= n; i++) {
    b.clear();
    for (int j = 1; j <= m; j++) b.push_back(make_pair(i, j));
    sort(b.begin(), b.end(), cmp);
    for (int j = 0; j < m; j++) {
      if (j != 0 &&
          a[b[j].first][b[j].second] == a[b[j - 1].first][b[j - 1].second]) {
        fa[find(get(b[j].first, b[j].second))] =
            find(get(b[j - 1].first, b[j - 1].second));
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    b.clear();
    for (int j = 1; j <= n; j++) b.push_back(make_pair(j, i));
    sort(b.begin(), b.end(), cmp);
    for (int j = 0; j < n; j++) {
      if (j != 0 &&
          a[b[j].first][b[j].second] == a[b[j - 1].first][b[j - 1].second]) {
        fa[find(get(b[j].first, b[j].second))] =
            find(get(b[j - 1].first, b[j - 1].second));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    b.clear();
    for (int j = 1; j <= m; j++) b.push_back(make_pair(i, j));
    sort(b.begin(), b.end(), cmp);
    for (int j = 0; j < m; j++) {
      if (j != 0 &&
          a[b[j].first][b[j].second] == a[b[j - 1].first][b[j - 1].second]) {
      } else {
        if (j != 0) {
          int x = find(get(b[j - 1].first, b[j - 1].second)),
              y = find(get(b[j].first, b[j].second));
          v[x].push_back(y);
          d[y]++;
        }
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    b.clear();
    for (int j = 1; j <= n; j++) b.push_back(make_pair(j, i));
    sort(b.begin(), b.end(), cmp);
    for (int j = 0; j < n; j++) {
      if (j != 0 &&
          a[b[j].first][b[j].second] == a[b[j - 1].first][b[j - 1].second]) {
      } else {
        if (j != 0) {
          int x = find(get(b[j - 1].first, b[j - 1].second)),
              y = find(get(b[j].first, b[j].second));
          v[x].push_back(y);
          d[y]++;
        }
      }
    }
  }
  memset(dist, -1, sizeof(dist));
  queue<int> q;
  for (int i = 1; i <= n * m; i++) {
    if (find(i) == i && d[i] == 0) {
      q.push(i);
      dist[i] = 1;
      in[i] = true;
    }
  }
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < (int)v[x].size(); i++) {
      d[v[x][i]]--;
      if (dist[v[x][i]] == -1 || dist[v[x][i]] < dist[x] + 1) {
        dist[v[x][i]] = dist[x] + 1;
      }
      if (d[v[x][i]] == 0) {
        q.push(v[x][i]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x = find(get(i, j));
      printf("%d ", dist[x]);
    }
    puts("");
  }
  return 0;
}
