#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAX = 1000005;
vector<vector<int> > grid;
vector<int> v;
map<int, int> comp;
vector<vector<pair<int, int> > > row;
vector<vector<pair<int, int> > > col;
vector<pair<int, int> > edges;
int eq[MAX];
bool vis[MAX];
int cc = 0;
int idx[MAX];
int sze[MAX];
int root(int x) {
  while (x != idx[x]) {
    idx[x] = idx[idx[x]];
    x = idx[x];
  }
  return x;
}
void join(int p, int q) {
  int i = root(p);
  int j = root(q);
  if (i == j) {
    return;
  }
  if (sze[i] < sze[j]) {
    idx[i] = j;
    sze[j] += sze[i];
  } else {
    idx[j] = i;
    sze[i] += sze[j];
  }
}
vector<int> g2[MAX];
vector<int> gr2[MAX];
int deg[MAX];
map<pair<int, int>, bool> mult;
queue<int> q;
vector<int> topo;
int main() {
  for (int i = 0; i < MAX; i++) {
    idx[i] = i;
    sze[i] = 1;
  }
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    grid.push_back(vector<int>(m, 0));
  }
  vector<pair<int, int> > space;
  for (int i = 0; i < n; i++) {
    row.push_back(space);
  }
  for (int i = 0; i < m; i++) {
    col.push_back(space);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x;
      scanf("%d", &x);
      grid[i][j] = x;
      v.push_back(grid[i][j]);
    }
  }
  sort(v.begin(), v.end());
  v.resize(distance(v.begin(), unique(v.begin(), v.end())));
  for (int i = 0; i < v.size(); i++) {
    comp[v[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      grid[i][j] = comp[grid[i][j]];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      row[i].push_back({grid[i][j], i * m + j});
      col[j].push_back({grid[i][j], i * m + j});
    }
  }
  for (int i = 0; i < n; i++) {
    sort(row[i].begin(), row[i].end());
    for (int j = 0; j < row[i].size() - 1; j++) {
      pair<int, int> a = row[i][j];
      pair<int, int> b = row[i][j + 1];
      edges.push_back({a.second, b.second});
      if (a.first == b.first) {
        join(a.second, b.second);
      }
    }
  }
  int ctt = 0;
  for (int i = 0; i < m; i++) {
    sort(col[i].begin(), col[i].end());
    for (int j = 0; j < col[i].size() - 1; j++) {
      ctt++;
      pair<int, int> a = col[i][j];
      pair<int, int> b = col[i][j + 1];
      edges.push_back({a.second, b.second});
      if (a.first == b.first) {
        join(a.second, b.second);
      }
    }
  }
  for (pair<int, int> i : edges) {
    int v1 = root(i.first);
    int v2 = root(i.second);
    if (mult[{v1, v2}] || v1 == v2) {
      continue;
    }
    mult[{v1, v2}] = true;
    g2[v1].push_back(v2);
    gr2[v2].push_back(v1);
    deg[v1]++;
  }
  for (int i = 0; i < m * n; i++) {
    if (deg[root(i)] == 0 && !vis[root(i)]) {
      vis[root(i)] = true;
      q.push(root(i));
    }
  }
  while (!q.empty()) {
    int first = q.front();
    q.pop();
    topo.push_back(first);
    for (int i : gr2[first]) {
      deg[i]--;
      if (deg[i] == 0) {
        q.push(i);
      }
    }
  }
  reverse(topo.begin(), topo.end());
  memset(deg, 0, sizeof deg);
  for (int i = 0; i < topo.size(); i++) {
    if (deg[topo[i]] == 0) {
      deg[topo[i]] = 1;
    }
    for (int j : g2[topo[i]]) {
      deg[j] = max(deg[topo[i]] + 1, deg[j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%d ", deg[root(i * m + j)]);
    }
    printf("\n");
  }
}
