#include <bits/stdc++.h>
using namespace std;
const int M = 1000010;
int row, col, Rmax[M], Cmax[M], last[M];
map<int, int> num;
vector<int> p;
vector<vector<int> > A, ans, visited;
vector<vector<vector<int> > > dx, dy;
vector<pair<int, int> > pos[M];
queue<pair<int, int> > q;
int bfs(int first, int second) {
  while (!q.empty()) q.pop();
  int i, maxx = 0;
  visited[first][second] = true;
  q.push(make_pair(first, second));
  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    maxx = max(maxx, max(Rmax[u.first], Cmax[u.second]));
    for (i = 0; i < 4; i++) {
      pair<int, int> v = make_pair(u.first + dx[u.first][u.second][i],
                                   u.second + dy[u.first][u.second][i]);
      if (!visited[v.first][v.second]) {
        visited[v.first][v.second] = true;
        q.push(v);
      }
    }
  }
  return maxx;
}
void put_ans(int first, int second, int k) {
  while (!q.empty()) q.pop();
  int i;
  ans[first][second] = k;
  q.push(make_pair(first, second));
  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    Rmax[u.first] = max(Rmax[u.first], k);
    Cmax[u.second] = max(Cmax[u.second], k);
    for (i = 0; i < 4; i++) {
      pair<int, int> v = make_pair(u.first + dx[u.first][u.second][i],
                                   u.second + dy[u.first][u.second][i]);
      if (ans[v.first][v.second] == -1) {
        ans[v.first][v.second] = k;
        q.push(v);
      }
    }
  }
}
int main() {
  int i, j, k, id = 0;
  scanf("%d%d", &row, &col);
  A.resize(row + 1);
  visited.resize(row + 1);
  ans.resize(row + 1);
  dx.resize(row + 1);
  dy.resize(row + 1);
  for (i = 0; i < row; i++) {
    A[i].resize(col + 1);
    visited[i].resize(col + 1);
    ans[i].resize(col + 1);
    dx[i].resize(col + 1);
    dy[i].resize(col + 1);
    for (j = 0; j < col; j++) {
      dx[i][j].resize(5);
      dy[i][j].resize(5);
      for (k = 0; k < 5; k++) dx[i][j][k] = dy[i][j][k] = 0;
    }
  }
  for (i = 0; i < row; i++)
    for (j = 0; j < col; j++) {
      visited[i][j] = false;
      ans[i][j] = -1;
      scanf("%d", &A[i][j]);
      p.push_back(A[i][j]);
    }
  sort((p).begin(), (p).end());
  for (i = 0; i < p.size(); i++)
    if (num[p[i]] == 0) num[p[i]] = ++id;
  for (i = 0; i < row; i++)
    for (j = 0; j < col; j++) {
      A[i][j] = num[A[i][j]];
      pos[A[i][j]].push_back(make_pair(i, j));
    }
  memset((last), (-1), sizeof(last));
  for (i = 0; i < row; i++) {
    for (j = 0; j < col; j++) {
      int v = A[i][j];
      if (last[v] != -1) {
        dy[i][j][0] = last[v] - j;
      }
      last[v] = j;
    }
    for (j = 0; j < col; j++) last[A[i][j]] = -1;
  }
  for (i = 0; i < row; i++) {
    for (j = col - 1; j >= 0; j--) {
      int v = A[i][j];
      if (last[v] != -1) {
        dy[i][j][1] = last[v] - j;
      }
      last[v] = j;
    }
    for (j = 0; j < col; j++) last[A[i][j]] = -1;
  }
  for (j = 0; j < col; j++) {
    for (i = 0; i < row; i++) {
      int v = A[i][j];
      if (last[v] != -1) {
        dx[i][j][2] = last[v] - i;
      }
      last[v] = i;
    }
    for (i = 0; i < row; i++) last[A[i][j]] = -1;
  }
  for (j = 0; j < col; j++) {
    for (i = row - 1; i >= 0; i--) {
      int v = A[i][j];
      if (last[v] != -1) {
        dx[i][j][3] = last[v] - i;
      }
      last[v] = i;
    }
    for (i = 0; i < row; i++) last[A[i][j]] = -1;
  }
  memset((Rmax), (0), sizeof(Rmax));
  memset((Cmax), (0), sizeof(Cmax));
  for (i = 1; i <= id; i++) {
    for (j = 0; j < pos[i].size(); j++) {
      int first = pos[i][j].first, second = pos[i][j].second;
      if (!visited[first][second]) {
        k = bfs(first, second);
        put_ans(first, second, k + 1);
      }
    }
  }
  for (i = 0; i < row; i++) {
    for (j = 0; j < col; j++) {
      printf("%d ", ans[i][j]);
    }
    printf("\n");
    ;
  }
  return 0;
}
